×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Challenging trick

Challenging trick

Challenging trick

(OP)
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 ????

RE: Challenging trick

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

RE: Challenging trick

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

M

--
Dr Michael F Platten

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources