How to Approximate The Solution for an Initial Value Problem?

I apologize in advance if this question is repeated, however I do not think it is.
I have an undamped mass-spring system that has external vibration. It is modeled by the equations below:
y"+4y=sin(1.9t)
y(0)=1
y'(0)=0
I need to write this system in vector form as first order differential equations. Then use ode45 to approxmate the initial value problem solution from 0<t<150 and plot the resulting x(t). This is what I have but I am not sure if this is the right approach:
f = @(t,x)[x(2)+(4*x(1));sin(1.9*t)]
[t,x] = ode45(f,[0,150],[1,0]);
plot(t,x)

 Réponse acceptée

Try
f = @(t,x) [x(2); sin(1.9*t)-4*x(1)];
[t,x] = ode45(f,[0,150],[1,0]);
plot(t,x)

4 commentaires

With all due respect, this appears to be a homework problem.
Giving full solutions to such are discouraged here.
John Smith
John Smith le 4 Déc 2021
Modifié(e) : John Smith le 4 Déc 2021
Star, thank you for assisting with the enforcement academic integrity, but if my professor did not want me to use external resources, they would not have let me complete this at home. Also, let me point out that I had already figured most it out, there was just one small mistake in my code, which Alan helped me with (moving over the 4*x(1) from one vector to another).
Alan, thank you so much for your help with this.
@John Smith — At my university, we had an Honor Code that required us to state and sign on each homework assignment, paper, examination, lab report and everything else: ‘I pledge on my honor that I have neither given nor received any unacknowledged aid on this (assignment, paper, exam, etc.).’ That was implied from the outset and never had to be repeated. Violating it could result in ‘severing the student’s connection to the University’. I guess times have changed in the interim, and in my opinion, not for the better.
Cheating is cheating.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by