Why results of the 'solve' are wrong?
Mostrar comentarios más antiguos
p_max=715.685424949238;
p_min=415.685424949238;
z_max=128.051406871193;
z_min=43.1985931288072;
D1_max=1128.05140687119;
D1_min=1043.19859312881;
angle=45;
y0=0:1:200;
p0=y0/sind(angle);
x0=p0*cosd(angle);
syms a b
q=sqrt((a-p_min)^2+(b-z_min)^2)-D1_min-sqrt((a-p_max)^2+(b-z_max)^2)+D1_max==0; %equation to solve
z_solve=solve(q,b);
z_value=subs(z_solve,a,p0);
z0=eval(z_value);
q1=sqrt((p0-p_min).^2+(z0-z_min).^2)-D1_min-sqrt((p0-p_max).^2+(z0-z_max).^2)+D1_max; %check the reults
2 comentarios
Steven Lord
el 26 de En. de 2023
You have not defined a variable named angle so when I run this code it tries to call the angle function with no input arguments and that throws an error. I recommend choosing a different name for your variable and editing your question to include the value of that variable.
ruiheng wu
el 26 de En. de 2023
Respuesta aceptada
Más respuestas (1)
Hi ruiheng,
I would stay out of the double world to first make sure everything is working as expected.
p_max=715.685424949238;
p_min=415.685424949238;
z_max=128.051406871193;
z_min=43.1985931288072;
D1_max=1128.05140687119;
D1_min=1043.19859312881;
angle=45;
y0=0:1:200;
p0=y0/sind(angle);
x0=p0*cosd(angle);
syms a b
q = sqrt((a-p_min)^2+(b-z_min)^2)-D1_min-sqrt((a-p_max)^2+(b-z_max)^2)+D1_max == 0; %equation to solve
Add ReturnConditions
z_solve = solve(q,b,'ReturnConditions',true);
vpa(z_solve.b,5)
vpa(z_solve.conditions,5)
%z_value = subs(z_solve,a,p0);
%z0 = eval(z_value)
%z0 = z_value(:,5);
%q1 = sqrt((p0-p_min).^2+(z0-z_min).^2)-D1_min-sqrt((p0-p_max).^2+(z0-z_max).^2)+D1_max %check the reults
%simplify(q1)
Only checking a few solutions, timed-out when trying to check all
for ii = 8:12, %1:numel(p0)
% verify that the value of a meets the condition for the solution
cond(ii) = simplify(subs(z_solve.conditions,a,p0(ii)));
% check the value of the solution for the value of a
check(ii) = simplify(subs(lhs(q),[a b],{p0(ii) subs(z_solve.b,a,p0(ii))}));
end
cond(8:12)
check(8:12)
1 comentario
ruiheng wu
el 27 de En. de 2023
Categorías
Más información sobre Common Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



