0
votes

I have to solve a second-degree differential equation and I specifically need the value of the first derivative of y at the final time point. My code is the following:

[T Y]=ode45(@(t y)vdp4(t,y,0.3),[0 1],[0.3/4,((3*0.3)^0.5)/2]);

I know the output will contain the values at which ode45 evaluated the function. To get the y values at specific time value at have it has been advised to give more than two time points in the MATLAB documentation. I did that too.

tspan=[0:0.01:1]
[T Y]=ode45(@(t y)vdp4(t,y,0.3),tspan,[0.3/4,((3*0.3)^0.5)/2]);

The T vector still does not have all the values from 0 to 1 (The last value is 0.39). This happens especially after multiple executions of ode45 function. I found something else in the MATLAB documentation: using "sol" structure to deval the values for specific t values. Is that the right way to go? For reference, my differential equation is in the following function.

function dy = vdp4(t,y,k)

dy = zeros(2,1);    % a column vector

dy(1)=y(2);
dy(2)=(y(2)^2-2*t*y(2)+2*y(1))/k+2;

end

Edit: I provided the parameter value. It should now be executable.

1
Do you get any error messages or warnings about the time step becoming too small or the values exceeding the floating point range? Please make your example executable by providing all the parameters, in this case k. - Lutz Lehmann
I provided the k value. Yes there were warnings about time step. - Mouli Modak
In general, the equation v' = (v^2+c)/k has a solution containing the tangent, thus exhibiting poles at finite times as you found at t=0.39262926. This is a feature of the exact solution, and thus can not be avoided in any half-ways competent numerical solution. Is there some physical background that would let you expect a bounded solution? It may be a modelling error. - Lutz Lehmann
Is it /k+2 as written or /(k+2)? - Lutz Lehmann
The differential equation is given by y''(t)=(((y'(t))^2 - 2ty'(t)+2y(t))/k)+2. - Mouli Modak

1 Answers

0
votes

Try to plot your solution, you will find the answer