Fluid Pathline using Euler's Method with MATLAB
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello.
I'm trying solve a problem of my course lecture in Fluid Mechanics.
We have velocity: u = y^2 - x^2 + t^2 at X-direction and v= 2xy + 20t at Y-direction.
To find the pathline of fluid we have the initial conditions that x0=1.5, y0=1 and t0=0 and we should use Euler's Method to determine the function.
I use the step of 0.001 for the time variable until t(final) = 10.
The problem in below program is debugging. Can someone help me ?
clear all
clc
f=@(x,y,t)y^2-x*2+t^2;
g=@(x,y,t)2*x*y + 20*t;
x0=input('\n Enter initial value of x i.e. x0: ');
y0=input('\n Enter initial value of y i.e. y0: ');
t0=input('\n Enter initial value of t i.e. t0: ');
tn=input('\n Enter the final value of t: ');
h=input('\n Enter the step length h: '); %example h=0.001
%Formula: y1=y0+h*function(x0,y0,t0);
fprintf('\n t x y');
while t0<=tn
fprintf('\n%4.3f %4.3f %4.3g',t0,x0,y0); %values of t and x and y
x1=x0+h*f(x0,y0,t0);
y1=y0+h*g(x0,y0,t0);
t1=t0+h;
x0=x1;
y0=y1;
end
Thank you very much.
댓글 수: 0
채택된 답변
Alan Stevens
2021년 3월 21일
편집: Alan Stevens
2021년 3월 21일
Replace
t1=t0+h;
by
t0=t0+h;
or add a line
t0 = t1;
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linearization Basics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!