I want to solve 2 equations with 2 variables but it cant be solved and the command window shows fsolve stopped because the last step was ineffective
1 次查看(过去 30 天)
显示 更早的评论
function main1
p=.153;
x0 = [-3000, -3000];
options = optimoptions('fsolve','display', 'iter');
[sol,fval,exitflag, output] = fsolve(@(x)fun(x,p),x0, options);
if exitflag <= 0
return
end
end
function xres = fun(x,p)
k0 = 2.536;
k1 = 1.354;
k2 = -4.775;
k3 = -2.772;
k4 = -0.235;
gsN = 10.567;
gzN = -0.467;
f_pi = 93.3;
d = 0.064;
X0 = 409.769;
f_k = 122.143;
m_pi = 139;
m_k = 498;
k = (3 * p* pi^2)^(1/3);
gsN = 10.567;
gzN = -0.467;
m1 = -(gsN*x(1) + gzN*x(2));
E = sqrt(k^2 +m1^2);
rho_s = (m1/pi^2)* (k*E- m1^2 * log((k+E)/m1));
F(1) = (k0*x(1)*X0^2)-(4*k1*x(1)*(x(1)^2 + x(2)^2))-(2*k2*x(1)^3)-(2*k3*X0*x(1)*x(2))-(2*d*X0^4/(3*x(1)))+(m_pi^2*f_pi) - (gsN*rho_s);
F(2) = (k0*x(2)*X0^2)-(4*k1*x(2)*(x(1)^2 + x(2)^2))-(2*k2*x(2)^3)-(k3*X0*x(1)^2)-(d*X0^4/(3*x(2)))+((sqrt(2)*m_k^2*f_k)-(f_pi*m_pi^2/sqrt(2))) - (gzN*rho_s);
xres = F;
end
* here i want to solve x(1) and x(2)
command window
No solution found.
fsolve stopped because the last step was ineffective. However, the vector of function
values is not near zero, as measured by the value of the function tolerance.
<stopping criteria details>
fsolve stopped because the sum of squared function values, r, changed by 9.991357e-14
relative to its initial value; this is less than max(options.FunctionTolerance^2,eps) = 1.000000e-12.
However, r = 2.189392e+13, exceeds sqrt(options.FunctionTolerance) = 1.000000e-03.
2 个评论
Amit Bhowmick
2021-7-1
Check your function and plot the residue, try to observe roots from the graph.
use this code
[X,Y]=meshgrid(-3000:50:-1,-3000:50:-1);
x=X(:);
y=Y(:);
for ii=1:numel(x)
res=myfun(x(ii),y(ii),p);
y1(ii)=res(1);
y2(ii)=res(2);
end
figure(2)
plot(y1)
hold
plot(y2)
回答(2 个)
Alex Sha
2021-7-3
Hi, the result below should be one solution
x1: -52.5485799573576
x2: 12.1032014174617
Pritha
2021-7-8
2 个评论
Amit Bhowmick
2021-7-8
A set of nonlinear equation can have more than one solution. However a set of linear eqution can have only one solution. For an example two straight line (Linear curve) can have only one point of intersection but two curve line can have more than one intersection. So both answer is correct unless you have any extra constraint on dependent varriable x1 and x2.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!