%% Question 1 % An ODE equation dy/dt = t*y^2 has an initial value y(-2) = 1 % A
ID: 3573802 • Letter: #
Question
%% Question 1
% An ODE equation dy/dt = t*y^2 has an initial value y(-2) = 1
% Apply the solver ode45 to calculate the numerical solution of the above ODE
% over the interval [-2, 2].
% You are required to use two approaches.
% Q1.1 (40%)
% Approach 1: Define an anonymous function func1, apply the solver ode45, and
% plot the numerical solution in blue.
% Write your code here:
%%
% Q1.2 (40%)
% Approach 2: Define a regular function func2 in a separate .m file, use the solve ode45, and plot the
% numerical solutions in red.
% Write your code here to call func2 and plot
Explanation / Answer
function p=ode()
tspan = [-2 2];
y0 = 1;
[t,y] = ode45(@(t,y) t*y^2, tspan, y0);
plot(t,y,'r*',t,y,'b--o')
end
ode()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.