Fluid Pathline using Euler's Method with MATLAB

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.

 採用された回答

Alan Stevens
Alan Stevens 2021 年 3 月 21 日
編集済み: Alan Stevens 2021 年 3 月 21 日

3 投票

Replace
t1=t0+h;
by
t0=t0+h;
or add a line
t0 = t1;

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeComputational Fluid Dynamics (CFD) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by