Clear Filters
Clear Filters

Not able to get real solution through syst solve

4 views (last 30 days)
I have been trying to solve the following equation and following is my code -
syms y t
f1 = -t^3/(3*(1 - y)^(2/3)) + (3 - t^2)^2/(6*(2 - t)*y^(2/3)) + (2*t)/(3*y^(2/3)) - (3 - 2*t)^2/(6*(2 - t)*(1 - y)^(2/3));
f2 = t - ((nthroot(y, 3)*(2/3)- (nthroot(1-y, 3)*((3 - 2*t)/(3*(2-t)))))/(nthroot(y, 3)*(((3-t^2))/(3*(2-t))) - nthroot(1-y, 3)*(t/3)));
[soly, solt] = solve([f1==0,f2==0],[y,t]);
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
ynum = vpa(soly);
tnum = vpa(solt);
res1 = arrayfun(@(i)vpa(subs(f1,[y t],[ynum(i) tnum(i)])),1:size(ynum,1));
res2 = arrayfun(@(i)vpa(subs(f2,[y t],[ynum(i) tnum(i)])),1:size(ynum,1));
res = [res1;res2];
sol = [];
for i = 1:size(res,2)
if abs(res(:,i)) < 1e-10
sol = [sol,[ynum(i);tnum(i)]];
end
end
solyt = unique(sol.','rows','stable').'
solyt = 
but I am only able to get complex solution. When I solved it through wolfram alpha I got real solution of x= 1 ^ y= 0.8132. What is wrong with my code?
  2 Comments
Star Strider
Star Strider on 4 Aug 2023
What function did you give to Wolfram Alpha?
Please post the Wolfram Alpha URL that contains the expression you gave it to solve. I expect that there are differrences between it and the posted MATLAB code.
Sabrina Garland
Sabrina Garland on 4 Aug 2023
Please see the attached image. I solved through system of equation. Isn't this what my Matlab code is doing as well?

Sign in to comment.

Answers (1)

Torsten
Torsten on 4 Aug 2023
Edited: Torsten on 4 Aug 2023
Always plot the functions before solving for common points and set initial values for the variables according to what you see in the plot.
syms y t
f1 = -t.^3./(3*(1 - y).^(2/3)) + (3 - t.^2)^2./(6*(2 - t).*y.^(2/3)) + (2*t)./(3*y.^(2/3)) - (3 - 2*t).^2./(6*(2 - t).*(1 - y).^(2/3));
f2 = t - ((nthroot(y, 3)*(2/3)- (nthroot(1-y, 3).*((3 - 2*t)./(3*(2-t)))))./(nthroot(y, 3).*(((3-t.^2))./(3*(2-t))) - nthroot(1-y, 3).*(t/3)));
fimplicit(matlabFunction(f1))
hold on
fimplicit(matlabFunction(f2))
[soly, solt] = vpasolve([f1==0,f2==0],[y,t],[0.5 1]);
ynum = vpa(soly);
tnum = vpa(solt);
res1 = arrayfun(@(i)vpa(subs(f1,[y t],[ynum(i) tnum(i)])),1:size(ynum,1));
res2 = arrayfun(@(i)vpa(subs(f2,[y t],[ynum(i) tnum(i)])),1:size(ynum,1));
res = [res1;res2];
sol = [];
for i = 1:size(res,2)
if abs(res(:,i)) < 1e-10
sol = [sol,[ynum(i);tnum(i)]];
end
end
solyt = unique(sol.','rows','stable').'
solyt = 
  20 Comments
Walter Roberson
Walter Roberson on 7 Aug 2023
vpasolve() only returns more than one solution under the conditions that:
  • the number of equations is the same as the number of free variables; and
  • the inputs are all polynomials in the free variables
If you have non-linear equations that are not polynomials, then vpasolve() will only ever return one solution... so much of your code is not doing anything useful.
Torsten
Torsten on 7 Aug 2023
Edited: Torsten on 7 Aug 2023
During the discussion, you used 3 different exponents (0.7,2/3 and 0.75) so that I don't know any more which results you address when you ask a question.
The display of the implicit graphs in different colors - I cannot explain it if you really get it with the code above.

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!