MATLAB: How to plot an ODE odeplotting Silly question but how can I plot a simple ODE like the following? My ODE is: dy/dt=1-(t/n)-y where n is an array n=[1 2 3 5 Inf] Best Answer Use for loop to solve equation 5 times for each nn = [1 2 3 5 inf];f = @(t,y,n) 1-t/n+y;for i = 1:length(n) [t,y] = ode45(f,[0 5],ic,[],n(i)); line(t,y)end Related SolutionsMATLAB: Solving a nonlinear ODE using ode45 There is nothing wrong with your ODE except that it takes off to infinity at about t=3. You have to decide if this is appropriate behaviour of if you need to change it.To see its behaviour, plot it:f = @(t,y) [y(2); y(3); -y(3)-y(2)-y(1)+y(1)^2];[t,y] = ode45(f,[0 30],[1;5;10]);figure(1)semilogy(t, y)grid MATLAB: How can i pull a corresponding y value for t=0.5, the matlab script below will out a list of values for y and t. Easiest is to use the interp1 function:y_t_05 = interp1(t, y, 0.5)y_t_05 = 1.093740231070597 Related Question4th order Runge-Kutta code that can solve for several intial conditionsSolving a ODE in matlabUsing ode45 for coupled equations
Best Answer