Not able to get real solution through syst solve
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Star Strider
el 4 de Ag. de 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.
Respuestas (1)
Torsten
el 4 de Ag. de 2023
Editada: Torsten
el 4 de Ag. de 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').'
20 comentarios
Walter Roberson
el 7 de Ag. de 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
el 7 de Ag. de 2023
Editada: Torsten
el 7 de Ag. de 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.
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!