How to add more than one conditions for an ode45 problem?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, This is my code in which 'b','phi' and 'VOLUME' are present:
format long
%input your entries here
density=1;%kg/m3
gravity=9;%m/s2
tension=46.5;%kg/s2
beta=(density*gravity)/tension;
for b=0:0.5:2
xini=1e-10;
zini=1e-10;
phiini=0;
phifin=150;
stepsize=1e-2;
V=1;
%code begins
phi1=deg2rad(phiini);
phi2=deg2rad(phifin);
f=@(phi,x)[b*cos(phi)/(2+beta*(x(2)/b)-(sin(phi)/(x(1)/b)));(b*sin(phi))/(2+beta*(x(2)/b)-(sin(phi)/(x(1)/b)))];
[phi,xa]=ode45(f,[phi1:stepsize:phi2],[xini zini]);
%Volume calculation
X=xa(:,1);
Z=xa(:,2);
VOLCUM=cumtrapz(Z,X);
position=find(VOLCUM<=V,1,'last');
VOLUME=VOLCUM(position)
My intention is to find the 'b' that gives me the required 'VOLUME' as well as 'phi' In other words, I want the code to loop until it gives me that 'b' which has 'VOLUME=1' and 'phi=60'. I am not sure how to proceed.
2 commentaires
Jan
le 12 Mai 2018
Modifié(e) : Jan
le 12 Mai 2018
The question is not clear. You want to get a "required V", but V is defined as a variable already. while is not an "operator" and I have no idea, where you want to apply &&. It is not clear, why you apply cumtrapz after the integration. Are you sure that this is useful?
Maybe you want to write a single-shooting method to estimate a parameter?
By the way: a:b:c is a vector already. There is no need to use [] for a horizontal concatenation.
Réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!