matlab几种求解器的选择fsolve-sole-vpasolve

文章目录

  • fsolve
  • solve
  • vpasovle
  • 总结
    • vpasovle的结果
    • fsovle的结果

fsolve

求数值解

result_x=fsolve(@my_fun,x0,options)

参数:

my_fun:待求解函数,作为一个.m文件
x0:初始值,向量,可以仅仅指定其中的几项

solve

强大的求解器。在方程组中求解析解,如果求不出来会用vpasovle去求数值解

vpasovle

求数值解。

yinzi = pi/180;
alpha_ON = 70*yinzi;
alpha_OM = 50*yinzi; 
alpha_MN = 20*yinzi;
% m = 4;
% n = 2;
% R = 10;
% if abs(m-n)*2*pi/9
%     theta_mn = abs(m-n)*2*pi/9;
% else
%     theta_mn = 2*pi-abs(m-n)*2*pi/9;
% end
%m = 3;
syms beta_m beta_n m;
theta_mn = 2*(m-1)*pi/9;
eq1 = sin(alpha_ON)*sin(beta_m)-sin(alpha_OM)*sin(beta_n) == 0;
eq2 = 2*sin(theta_mn/2)*sin(alpha_ON)*cos(theta_mn/2+beta_m) - sin(alpha_MN)*sin(beta_n+alpha_ON) == 0;
eq3 = beta_m + alpha_OM + theta_mn - beta_n - alpha_ON == 0;
sol = vpasolve([eq1, eq2, eq3], [beta_m, beta_n ,m]);

%sol = solve([eq1, eq2], [beta_m, beta_n]);
%disp(sol);
ans_beta_m = sol.beta_m*180/pi
ans_beta_n = sol.beta_n*180/pi
R = 10;
pho_x = R/sin(alpha_OM)*sin(sol.beta_m)

总结

求解发现vpasolve的求解器求出了错误的解,fsolve求出了正确的解。

vpasovle的结果

pho_x =
 
-1.2420365392830642226815671080075

fsovle的结果

pho_x =

   10.0000

你可能感兴趣的:(matlab,算法,开发语言,数学建模)