How to add more than one conditions for an ode45 problem?

조회 수: 3 (최근 30일)
Purush otham
Purush otham 2018년 5월 12일
편집: Purush otham 2018년 5월 12일
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
Jan
Jan 2018년 5월 12일
편집: Jan 2018년 5월 12일
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.
Purush otham
Purush otham 2018년 5월 12일
Hi thanks for your comment. Edited the original question. The three major parameters here are: 'phi','b' and 'VOLUME'.
My intention is to predefine 'VOLUME' and 'phi' and get the required 'b'.
The use of cumtrapz here is to find the area under plot. (%The final value of cumtrapz is same as trapz)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by