(adsbygoogle = window.adsbygoogle || []).push({}); 1. The problem statement, all variables and given/known data

I am studying a forced undamped oscillator with matlab governed by the equation:

y'' + [itex]\omega[/itex]_{o}y = 2Cos([itex]\omega[/itex]t)

First I have to write a function that can be solved by the solver ode45.

Here is where I am stuck. Matlab just spits error messages at me when I try to run the solver.

It would be awesome if someone could check my mfile and see where I am going wrong.

2. Relevant equations

y'' + [itex]\omega[/itex]_{o}y = 2Cos([itex]\omega[/itex]t)

y(0)=0

y'(0)=0

[itex]\omega[/itex]_{o}= 2

[itex]\omega[/itex] = 1.95+[itex]\epsilon[/itex]

e = a small number

3. The attempt at a solution

This is my m-file, descriptions in green

-----------------------------------------------

function [ydot] = occi( t,y ) % The name of the function is occi

Wo = 2; % The value of [itex]\omega[/itex]_{o}

e = 9*8*10^-3; % Value for [itex]\epsilon[/itex]

w = 1.95+e; % The value for [itex]\omega[/itex]

ydot = zeros(2,1); %Creates a 2rows 1column matrix to contain the system of Ode

ydot(1) = y(1); %sets y' = y1

ydot(2) = 2*cos(w*t)-(Wo^2)*y; %sets Y'' = 2Cos([itex]\omega[/itex]t) - [itex]\omega[/itex]_{o}y

end

------------------------------------------

Then I run this script:

>>[tout, yout] = ode45(@occi, [0 2*pi], [0; 0]);

and matlab slaps me in the face with:

??? In an assignment A(I) = B, the number of elements in B and

I must be the same.

Error in ==> occi at 7

ydot(2) = 2*cos(w*t)-(Wo^2)*y;

Error in ==> odearguments at 98

f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ==> ode45 at 172

[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

So, I don't get what's wrong. Thanks for help. (is it presumptuous to write that?)

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: 2nd order nonhomogenus differential equation in matlab

**Physics Forums | Science Articles, Homework Help, Discussion**