Not able to get real solution through syst solve

2 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2023-8-4
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 2023-8-4
Please see the attached image. I solved through system of equation. Isn't this what my Matlab code is doing as well?

请先登录,再进行评论。

回答(1 个)

Torsten
Torsten 2023-8-4
编辑:Torsten 2023-8-4
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 个评论
Walter Roberson
Walter Roberson 2023-8-7
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 2023-8-7
编辑:Torsten 2023-8-7
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by