Clear Filters
Clear Filters

bvp using secant method and range kutta 4th order

1 view (last 30 days)
It is asked to solve m* d^2 y/dt=-g-gama*dy/dt. the values given are alredy in the code
what is wrong with this function: ___________________________________________________________________
%3.
[value,x0,numIter] = f_secante(@find0_p3,0, 1, 0.0001, 1000);
%[x,v]
m=0.01; g=9.8; gama=0.05;
f=@(x,t)[x(2); -(g*m+gama*x(2))/m];
x=[x0;0.3];t=0;tf=20; dt=0.01;
t=0;
time=[t];
mat=[x];
while t<tf
[t,x] = f_rk4(f,t,x,dt);
time=[time,t];
mat=[mat,x];
end
plot(time,mat(1,:))
fprintf('%s %f\n','y(0)=',x0)
so that______________________________________________________________
function [value,x0,numIter] = f_secante(f, a, b, tol, nmax)
%[value,x0,numIter] = f_secante(f, a, b, tol, nmax)
if f(a)==0
x0=a; numIter=0; value=0;
return;
end;
if f(b)==0
x0=b; numIter=0; value=0;
return;
end;
x1=a; x2=b;
for k=1:nmax
x3=x2-(((x2-x1)*f(x2))/(f(x2)-f(x1)));
if abs((x3-x2)/x2)<tol; x0=x3; numIter=k;
continue;
else
x1=x2;x2=x3;
end
if f(x3)~=0 ; x0 = a; numIter=k; value=f(x3);
return
end
end
and______________________________________________________________________
function z=find0_p3(y0)
%[x,v]
m=0.01; g=9.8; gama=0.05;
f=@(x,t)[x(2); -(g*m+gama*x(2))/m];
x=[y0;0.3];t=0;tf=20; dt=0.01;
while t<tf
[t,x] = f_rk4(f,t,x,dt);
end
z=x(1);
end
____________________________________________________________________
the question is that x0 that is x so that y(20)=0, is giving me wrong because when i plot the graph, y(20)=-40.
Can you help me?
if true
% code
end

Answers (0)

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!