I am trying to solve a non linear simultaneous equation using NR method.The program does not converges.I know the exact solution and if the initial value is set to exact value then the program converges in one step.
1 次查看(过去 30 天)
显示 更早的评论
I have attached the m file with the initial values of the three unknowns equal to its exact values (i.e in the x vector) as a result the value converges in a single iteration.
If i initialize value little different from the exact solution.Then the value does not converges.I want my program to converge with values different from exact initial value.The exact value Of X vector is
x=[0.033670275;0.251;1168]
If the initial X vector is changed from the above values then the program does not converges. Please help me in this regard.
0 个评论
采纳的回答
Are Mjaavatten
2017-12-15
First: Your script parameter_function_matrix.m is a bit confusing, with your exceedingly long expressions. It would be easier to read and debug if you defined some variables that you could use to build your function expressions. Example: For the first element of F you could write:
f = zeros(3,1);
a = 7.36;
b = 24.2;
c = 6.83;
d = 30.4;
f(1) = a-(b+x(2)*(c-a))/x(3)-(a-(d-a*x(2))/x(3))*exp((b+c*x(2)-d)/x(1)/50);
Convergence of the Newton-Raphson method may depend strongly on the initial values, but starting not too far from the known solution it converges in most cases. In the script below, I start at a random values normally distributed around the correct solution, using a standard deviation equal to the solution value. It converges in about half the cases, although sometimes to another solution. A narrower distribution will converge more often.
xsol = [0.033670275;0.251;1168]; % Sought solution
x0 = xsol.*(1+randn(3,1)); % Try starting a bit away from the solution
% Newton-Raphson:
x = x0;
for i = 1:50
[f,J] = patro(x);
dx = J\f(:);
x = x - dx;
if norm(f(:))< 1e-5
break;
end
end
if i >= 50
disp('No convergence')
else
fprintf('%12s %12s\n','x','g');
for i = 1:3
fprintf('%12g %12g\n',x(i),f(i));
end
end
I have made some minimal edits to your (exhausting) function code, and attached it as Matlab function patro.m.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!