Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Challenging trick

Status
Not open for further replies.

Star1976

Materials
Jan 31, 2005
6
Hi Guys
Here is a challenging trick for you:

Suppos that you have this star.m file containg an ODE with the needed parameters:

function dC = star(t,C)
dC = zeros(1,1);
Gn=1;
N=2;
f=3;
w=4;
dC = (1/2)*Gn*N*C(1)+f*cos(w*t-C(1))

Now to solve this equation you simply create the following file:

t =linspace(0,5,100);
C0 = [0];
[t,C] = ode45('star', t, C0);

Now, the trick is how to solve this equation for a range of one of the given parameters (for example w=0,1,2,3,4,5,6). You will need to use for loop but the question is where to insert the loop ????
 
Replies continue below

Recommended for you

How about using global variables?

the function:
function dC = star(t,C)
dC = zeros(1,1);
Gn=1;
N=2;
f=3;
global w;
dC = (1/2)*Gn*N*C(1)+f*cos(w*t-C(1))

the script:
global w;
t =linspace(0,5,100);
C0 = [0];
for w = 0:6
[t,C] = ode45('star', t, C0);
%save t and C so they're not rewritten
end

 
There is a section in the ODE "help" pages which deals explicitly with passing parameters to odefiles.

M

--
Dr Michael F Platten
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor