Not able to get real solution through syst solve
Show older comments
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]);
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').'
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
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
on 4 Aug 2023
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').'
20 Comments
Sabrina Garland
on 4 Aug 2023
Torsten
on 4 Aug 2023
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.
Sabrina Garland
on 4 Aug 2023
Sabrina Garland
on 5 Aug 2023
Edited: Sabrina Garland
on 5 Aug 2023
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').'
Sabrina Garland
on 5 Aug 2023
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.
Sabrina Garland
on 5 Aug 2023
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').'
Sabrina Garland
on 5 Aug 2023
Alex Sha
on 5 Aug 2023
There are real value solutions:
No. t y
1 1 0.813246375971974
2 -0.363651385158899 0.171674002790231
3 1.04761409922947 0.800920773640283
Sabrina Garland
on 5 Aug 2023
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').'
[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').'
[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').'
Sabrina Garland
on 5 Aug 2023
Sabrina Garland
on 5 Aug 2023
Sabrina Garland
on 7 Aug 2023
Edited: Walter Roberson
on 7 Aug 2023
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.
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.
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



