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 ????
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
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
M
--
Dr Michael F Platten