How to express a function both time and spatial dimension dependent?
显示 更早的评论
Hi there,
It seems an easy one but I guess it is not that easy. I have a fluid flowing through a vessel. I want to measure its velocity u1 and u2. the vessel coordinetes from the lateral position x=0 to x=1 in time from t=0 to t=3. The code is :
ii=101;
dt=0.1;
t = 0:dt:10;
dx=0.01; %step size
fik=0.4;
for i=1:ii;
x=(i-1)*dx;
H1D=0.1;
H1=0;
A=0;
AD=0.1;
fikness=fik*sin(pi*x);
ub1(i)=(c1b-H1D*(x-0.5)+AD/2*(x-0.5)^2)/(H1-0.5*fikness-A*(x-0.5));
ub2(i)=(c2b+H1D*(x-0.5)-AD/2*(x-0.5)^2)/(1-H1+0.5*fikness+A*(x-0.5));
end
H1D=H1D+dt*H1DDOT %------lets say these H1D, H1DDOT, H1 are time dependent functions.
H1=H1+dt*H1
AD=AD+dt*ADDOT;
A=A+dt*AD
Matlab runs the program above but it is not showing time. For example if I want to see in time t=2 what are the velocities u1 and u2 over the whole vessel (from x=0 to x=1)? How can I plot and see the results Thanks in advance
回答(1 个)
Amit
2014-1-27
Well, your time is stored in vector t. So lets say you want to plot ub1 versus time, it will be:
plot(t,ub1);
3 个评论
Amit
2014-1-27
I think there is something wrong in this code too. You are not looping through time actually. I think this code is done to get velocities at t = 0.1 sec. You did not go further.
You have to loop through time as well.
Just a piece of advice: Matlab have good numerical integrators like ode45 which is more stable that simple euler forward integration that you're doing here.
Meva
2014-1-27
Amit
2014-1-27
Like I said, you have done your calculation for the first time step only. You need to go through more time loops.
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!