Solve/Plot Second Order DiffEq w/ Two Inital Conditions
Show older comments
I have to solve and plot the result of a second order differential equation using ode45 in MATLAB. I have used ode45 before and cannot figure out how to put a second inital condition in my statements when using a simple code like this (an example of code I have used before):
t2span = [5 10];
v02 = 0; %one initial condition
u2=0; %constant
[t2,v2] = ode45(@(t2,v2) u2-abs(v2)*v2, t2span, v02); %simple ode45 statement
This is the equation given: 𝑥̈ =6sin(𝑡)−𝑥^5 −0.6𝑥̇ , and I must plot x(t) from t=0 to t=240seconds, with initial conditions x(0)=2, 𝑥̇(0)=3.
This is what I have, it works but when I try to do the second part of the problem it makes me think it is incorrect (the second part makes me split the diffeq into its three terms and solve them and then plot them on a combined graph).
M=@(t,X)[X(2);6*sin(t)-X(1).^5-0.6*X(2)] %creating a function
sol = ode45(M,[0 240],[2 3]); %solving using ode45
fplot(@(x)deval(sol,x,1), [0, 240]) %plotting
Please let me know if this is correct or if there is an easier way to do this because I am not sure if this is correct. I got this code from looking up information on ode45 and other ways of solving diffeqs in MATLAB.
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations 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!


