MATLAB: What’s the difference in matlab’s code when i want to solve this equation y”=a,y(0)=0,y(1)=0 and this equation y”=a,y'(0)=0,y(1)=0???/

code in matlabdifferential equationsMATLAB

I tried to solve this equation y''=a,y(0)=0,y(1)=0 in matlab and i wrote this code: T=1000; >> dt=.01; >> N=round(T/dt)+1; >> t=(0:dt:T); >> a=.01; >> >> >> >> y(1)=.25; >> y(2)=1; >> >> for i=2:N-1;
y(i+1)=2*y(i)-y(i-1)+a*dt^2; end
Now i want to solve the equation y''=a,y'(0)=0,y(1)=0
What is the difference when i will write the matlab's code?????

Best Answer

For the first problem, you will have to solve the linear system of equations
y(1) = 0
y(3) - 2*y(2) + y(1) = a*dt^2
...
y(n) - 2*y(n-1) + y(n-2) = a*dt^2
y(n) = 0
For the second problem, you will have to solve the linear system of equations
y(1) - y(2) = 0
y(3) - 2*y(2) + y(1) = a*dt^2
...
y(n) - 2*y(n-1) + y(n-2) = a*dt^2
y(n) = 0
with
dt = 1/(n-1)
Best wishes
Torsten.