Not able to get real solution through syst solve

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

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.
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)

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

In the Attached image in the comment section of my question, wolfram alpha is giving me multiple solution for t and y. Will the code is only meant to give stable solutions?
If the code can solve your system analytically (like it was the case in your previous question), it will give you all solutions. This is not the case here. MATLAB can only solve numerically, and it will return one solution at a time, depending on your initial guess.
So instead of 0.5 and 1 as initial guess, if I put 0.8 and 1 as my guess that would change the solution. Will the solution of Matlab be reliable?
Will the solution of Matlab be reliable?
Your code from above substitutes the solutions found into the equations and only prints them to screen if the absolute function values are less than 1e-10.
Couldn't you interprete what your code does ?

My code is solving the simultaneous equation so no matter what initial value I put it will produce surrounding solutions. Thanks @Torsten

I also tried to solve for this - When y has exponent of 0.3 but Matlab couldn't solve it. Why is that?

 syms y t
 f1 = -0.3*t^3/(3*(1 - y)^(0.7)) + 0.15*(3 - t^2)^2/((2 - t)*y^(0.7)) + (0.6*t)/(y^(0.7)) - 0.15*(3 - 2*t)^2/((2 - t)*(1 - y)^(0.7));
 f2 = t - (((y^(0.7))*(2/3)- (((1-y)^(0.7))*((3 - 2*t)/(3*(2-t)))))/((y^(0.7))*(((3-t^2))/(3*(2-t))) - ((1-y)^(0.7))*(t/3))); 
[soly, solt] = solve([f1==0,f2==0],[y,t]); 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').'
Again: Plot the functions and choose the initial guess according to where the plots intersect. There is no other way in MATLAB, and I already gave you the code to use in my above answer.
syms y t
f1 = -0.3*t.^3/(3*(1 - y).^(0.7)) + 0.15*(3 - t.^2)^2./((2 - t).*y.^(0.7)) + (0.6*t)./(y.^(0.7)) - 0.15*(3 - 2*t).^2./((2 - t).*(1 - y).^(0.7));
f2 = t - (((y.^(0.7))*(2/3)- (((1-y).^(0.7)).*((3 - 2*t)./(3*(2-t)))))./((y.^(0.7)).*(((3-t.^2))./(3*(2-t))) - ((1-y).^(0.7)).*(t/3)));
fimplicit(matlabFunction(f1))
hold on
fimplicit(matlabFunction(f2))
[soly, solt] = vpasolve([f1==0,f2==0],[y,t],[0.3 -0.5]);
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
%Columns of solyt are solutions for y and t. Thus there are 9 (y,t) pairs %found that satisfy f1==0 and f2==0.
solyt = unique(sol.','rows','stable').'
solyt = 
@Torsten solution of t can only be between 0 and 1 and solution of y between 0.5 and 1. Since we know there are multiple solution. How can I get those solution?
By choosing the initial guesses near to where the red and blue curves intersect and inserting the values in the vpasolve command, with first entry for y and second entry for t like I did here:
[soly, solt] = vpasolve([f1==0,f2==0],[y,t],[0.3 -0.5]);
I saw that their is an intersection near y = 0.3 and t = -0.5.
Thanks @Torsten for all the help. One last thing. I can see in the figure that t=1 has two solution, one at y= 0.78 and one at y=.89. But no matter what initial value I put I can't let my Matlab print 0.89 and 1 as solution, why is that?
syms y t f1 = -t.^3./(4*(1 - y).^(3/4)) + (3 - t.^2)^2./(8*(2 - t).*y.^(3/4)) + (t)./(2*y.^(3/4)) - (3 - 2*t).^2./(8*(2 - t).*(1 - y).^(3/4)); f2 = t - (((y.^(1/4))*(2/3)- (((1-y).^(1/4)).*((3 - 2*t)./(3*(2-t)))))./((y.^(1/4)).*(((3-t.^2))./(3*(2-t))) - ((1-y).^(1/4)).*(t/3))); fimplicit(matlabFunction(f1)) hold on fimplicit(matlabFunction(f2)) [soly, solt] = vpasolve([f1==0,f2==0],[y,t],[0.99 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').'
I don't see any solution lines intersecting near y = 0.89 and t = 1 in the plot.
syms y t
f1 = -t.^3./(4*(1 - y).^(3/4)) + (3 - t.^2)^2./(8*(2 - t).*y.^(3/4)) + (t)./(2*y.^(3/4)) - (3 - 2*t).^2./(8*(2 - t).*(1 - y).^(3/4));
f2 = t - (((y.^(1/4))*(2/3)- (((1-y).^(1/4)).*((3 - 2*t)./(3*(2-t)))))./((y.^(1/4)).*(((3-t.^2))./(3*(2-t))) - ((1-y).^(1/4)).*(t/3)));
fimplicit(matlabFunction(f1))
hold on
fimplicit(matlabFunction(f2))
[soly, solt] = vpasolve([f1==0,f2==0],[y,t],[0.99 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 = 
@Torsten this is my Matlab figure with same code. It has solution at y=.89
There are real value solutions:
No. t y
1 1 0.813246375971974
2 -0.363651385158899 0.171674002790231
3 1.04761409922947 0.800920773640283
@Alex Sha How do you get all these solutions? What's the code?
Because you modified your functions within this post, I don't know if I'm still up-to-date.
syms y t
f1 = -t.^3./(4*(1 - y).^(3/4)) + (3 - t.^2)^2./(8*(2 - t).*y.^(3/4)) + (t)./(2*y.^(3/4)) - (3 - 2*t).^2./(8*(2 - t).*(1 - y).^(3/4));
f2 = t - (((y.^(1/4))*(2/3)- (((1-y).^(1/4)).*((3 - 2*t)./(3*(2-t)))))./((y.^(1/4)).*(((3-t.^2))./(3*(2-t))) - ((1-y).^(1/4)).*(t/3)));
fimplicit(matlabFunction(f1))
hold on
fimplicit(matlabFunction(f2))
[soly, solt] = vpasolve([f1==0,f2==0],[y,t],[0.81 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 = 
[soly, solt] = vpasolve([f1==0,f2==0],[y,t],[0.9 0.8]);
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 = 
[soly, solt] = vpasolve([f1==0,f2==0],[y,t],[0.05 -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 = 

@Torsten I didn't change the function and running your code in my Matlab mobile is still giving me figure that I attached which is showing me solution as y= 0.89 at t=1. Why is that?

My code cannot show the plot you attached because the plot from the code I use can only have two colours. What MATLAB release do you use ?
@Torsten I know. It shouldn't show many color graphs. This is Matlab mobile v6.1.0
@Torsten Please help.
When I changed the power in f2 function from 0.7 to 0.3, I am still getting same answer of t=1 and y=0.9038.
syms y t
f1 = -0.3*t.^3/(3*(1 - y).^(0.7)) + 0.15*(3 - t.^2)^2./((2 - t).*y.^(0.7)) + (0.6*t)./(y.^(0.7)) - 0.15*(3 - 2*t).^2./((2 - t).*(1 - y).^(0.7));
f2 = t - (((y.^(0.3))*(2/3)- (((1-y).^(0.3)).*((3 - 2*t)./(3*(2-t)))))./((y.^(0.3)).*(((3-t.^2))./(3*(2-t))) - ((1-y).^(0.3)).*(t/3)));
fimplicit(matlabFunction(f1))
hold on
fimplicit(matlabFunction(f2))
[soly, solt] = vpasolve([f1==0,f2==0],[y,t],[0.7 0.9])
soly = 
0.9038609440509542648033735347765
solt = 
1.0
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]
res = 
sol = [];
for i = 1:size(res,2)
if abs(res(:,i)) < 1e-10
sol = [sol,[ynum(i);tnum(i)]];
end
end
%Columns of solyt are solutions for y and t. Thus there are 9 (y,t) pairs
%found that satisfy f1==0 and f2==0.
solyt = unique(sol.','rows','stable').'
solyt = 
Why is Matlab mobile still giving me figures with multiple colors and now producing same answer when powers are changed. I am stuck. Please help
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.
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.

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2023a

Asked:

on 4 Aug 2023

Edited:

on 7 Aug 2023

Community Treasure Hunt

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

Start Hunting!