Parametrizing ode45
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everybody,
I am new to Matlab and would request some help with numerically solving an ODE. The equations themselves are very simple as given below:
u1'=-u1*u2*cos(theta) u2'=-u1^2*cos(theta)
Where u1 is u1(z) and u2 is u2(z) and the derivative is w.r.t z. I would like to generate plots for z=[0,5] and theta=[-2pi,2pi]. I tried the simple case where theta is fixed to pi and obtained a nice plot for u1,u2 vs z.
function dydz=amstrong(z,y)
theta=pi;
dydz=zeros(size(y));
u1=y(1);
u2=y(2);
dydz(1)=-u1*u2*cos(theta);
dydz(2)=u1^2*cos(theta);
end
I would like to do this for a range of theta values. I am not sure how to proceed.
The script to get results is as shown below:
%%%%%%%
tic
%%%%%%%
clear % Clear memory
z0=(0:0.0001:5); % Vector that goes from 0 to 5
y0=[1,0]; % IC u1=1 and u2=0
%Calling ode45
%
[z,y]=ode45('amstrong',z0,y0);
%Plotting the result.The plot is of u^2 v/s z.
plot(z,y.^2)
%%%%%%%%
toc
%%%%%%%%
My objective to get a series of graphs on the same plot as theta is varied over a large range. I did take a look at the possibility of a function calling another function, but it was very confusing.
Any help will be much appreciated.
Thank you.
PS# Running Matlab2010a x64 on Windows7.
0 commentaires
Réponses (4)
Jan
le 13 Août 2011
See this thread, where Jiro explains using anoymous function for parameterization:
0 commentaires
Abhishek Murthy
le 13 Août 2011
1. declare theta as global variable in both the functions.
2. In the "script to get results", vary theta in a loop. Inside the loop call ode45. In every loop iteration, armstrong will be called upon to provide the system definition. It would read the current value of theta as its globally visible.
3. process [z,y] vectors in each loop into some data structure (maybe a 3d matrix or a linked list) where the third dimension indexes various values of theta
I hope this helps.
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!