Solving a second order differential equation

2 vues (au cours des 30 derniers jours)
Mahir Ulas Pektas
Mahir Ulas Pektas le 6 Jan 2020
Hello everyone,
I have the differential equation ? 2? ?? 2 + 10 ?? ?? + 16? = 16 ;
I need to solve the equation using ode45 with the inital values of y=0 and dy_dt = 0. I have a time interval of t= 0 to 8.63644. But apparently the script also has to find the maximum values of y and dy_dt with corresponding time t. I managed to wrote 2 seperate scripts for it which are my maincode function and seperate equation function.
So for the main code I have;
clear all
time_interval = [0 215911/25000];
initial = [0 0];
[t,y] = ode45(@Q5, time_interval, initial);
plot(t,y(:,1)), title('y vs t')
figure
plot(t, y(:,2)), title('dy_dt vs t')
And for the equation script, I have;
function results = Q5(t,y)
results = [y(2);10*y(2)-(16*y)+16];
But I keep getting these specific errors:
Error using odearguments (line 95)
Q5 returns a vector of length 3, but the length of initial conditions vector is 2. The vector returned by Q5 and the initial conditions vector must have the same number of
elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Q5_maincode (line 7)
[t,y] = ode45(@Q5, time_interval, initial);
I have tried using size function to equate to arrays but it did not work.
My inquiry is that which functions should I use to rectify the errors? Or how do I fix the errors so to say. Any help would be appreciated, thanks in advance.
Version: 9.6

Réponses (1)

J. Alex Lee
J. Alex Lee le 7 Jan 2020
In you function Q5, your 2nd row has a typo, using y instead of y(1)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by