Effacer les filtres
Effacer les filtres

how to solve nonlinear shooting method

4 vues (au cours des 30 derniers jours)
liyana nadirah
liyana nadirah le 20 Mai 2020
f = @(x,y,z) ((z^2)*(x^-3))-(9*(y^2)*(x^-5))+(4*x);
fy = @(x,y,z) -(18*y*(x^-5));
fz = @(x,y,z) (2*z*(x^-3));
a=1; b=2; alpha =1; beta =log(256); tol=10^(-4); n=20; m=10; h=0.05;
tk = (beta-alpha)/(b-a);
fprintf('Nonlinear shooting method\n\n');
fprintf(' x(i) w(i)\n');
w1 = zeros(1,n+1);
w2 = zeros(1,n+1);
h = (b-a)/n;
k = 1;
while k <= m
w1(1) = alpha;
w2(1) = tk;
u1 = 0 ;
u2 = 1;
for i = 1 : n
x = a+(i-1)*h;
t = x+0.5*h;
k11 = h*w2(i);
k12 = h*f(x,w1(i),w2(i));
k21 = h*(w2(i)+0.5*k12);
k22 = h*f(t,w1(i)+0.5*k11,w2(i)+0.5*k12);
k31 = h*(w2(i)+0.5*k22);
k32 = h*f(t,w1(i)+0.5*k21,w2(i)+0.5*k22);
k41 = h*(w2(i)+k32);
k42 = h*f(x+h,w1(i)+k31,w2(i)+k32);
w1(i+1) = w1(i)+(k11+2*(k21+k31)+k41)/6;
w2(i+1) = w2(i)+(k12+2*(k22+k32)+k42)/6;
k11 = h*u2;
k12 = h*(fy(x,w1(i),w2(i))*u1+fz(x,w1(i),w2(i))*u2);
k21 = h*(u2+0.5*k12);
k22 = h*(fy(t,w1(i),w2(i))*(u1+0.5*k11)+fz(t,w1(i),w2(i))*(u2+0.5*k21));
k31 = h*(u2+0.5*k22);
k32 = h*(fy(t,w1(i),w2(i))*(u1+0.5*k21)+fz(t,w1(i),w2(i))*(u2+0.5*k22));
k41 = h*(u2+k32);
k42 = h*(fy(x+h,w1(i),w2(i))*(u1+k31)+fz(x+h,w1(i),w2(i))*(u2+k32));
u1 = u1+(k11+2*(k21+k31)+k41)/6;
u2 = u2+(k12+2*(k22+k32)+k42)/6;
end
if abs(w1(n+1)-beta) < tol
i = 0;
fprintf(' %11.8f %11.8f\n', a, alpha);
for i = 1 : n
j = i+1;
x = a+i*h;
fprintf(' %11.8f %11.8f\n', x, w1(j));
end
fprintf('\nConvergence in %d iterations t=%11.7f \n\n', k, tk);
break;
else
tk = tk-(w1(n+1)-beta)/u1;
k = k+1;
end
end
hai guys this is my coding for nonlinear shooting method but i don't know what wrong with this coding, because the answer not appear. so please help me to fix this coding please.

Réponses (1)

Neelanshu
Neelanshu le 6 Fév 2024
Hi Liyana,
I understand from your query that you are interested in identifying the problem with the code for the non-linear shooting method.
During debugging, I have found that at k=1 and i=14, k31 and k22 approach infinity. This divergence indicates that the method is not converging, which causes subsequent values of w1, w2, and tk to be updated as NaN (Not a Number). This is due to an 'Inf - Inf' operation that occurs when the function f is called. As a result, for all the following values of k, w1 and w2 become vectors filled with NaN values.
Since the solution never converges you don't see any output in the command window. A good choice of tk can improve convergence.
Hope this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by