![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1362498/image.png)
Solving and plotting 2nd order ODE
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to solve the equation y''+sin(y)=0, and plot the results at time 0, 0.1, 0.7, 1.5, 3.0, on a graph.
I tried using this code so far to find the solution, but I am unable to plot the result, '2*atan(exp(C1-t)). I think it's because of the 'C1' in the solution, but I'm not sure how to get rid of it.
>> syms y(t)
>> ode = diff(y,t) == -sin(y)
ode(t) =
diff(y(t), t) == -sin(y(t))
>> ySol(t) = dsolve(ode)
ySol(t) =
2*atan(exp(C1 - t))
0
0 commentaires
Réponses (1)
Piotr Balik
le 20 Avr 2023
Modifié(e) : Piotr Balik
le 20 Avr 2023
This is constant, whose numerical value is depending on initial conditions.
You can either specify it directly, per Solve system of differential equations - MATLAB dsolve (mathworks.com)
bnds = y(0) == -0.123
ySol(t) = dsolve(ode, bnds)
But you can also try to solve it substituting to general solution analytically:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1362498/image.png)
Plotting and the example code
syms y(t)
ode = diff(y,t) == -sin(y)
bnds = y(0) == -0.123
ySol(t) = dsolve(ode,bnds)
tv = [0, 0.1, 0.7, 1.5, 3.0];
yv = ySol(tv)
figure,
plot(tv,yv,'o-')
0 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!