在循环覆盖值:Matlab的 [英] overwritten values in loops: Matlab

查看:260
本文介绍了在循环覆盖值:Matlab的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code以下,当我执行它,UB,U,P,Q阵列因为在code II = 101显示像101倍。我的意思是循环不起作用。你可以看看它,请

The code below , when I execute it, ub,u, p, q arrays are shown like 101 times since ii=101 in the code. What I mean is the loop does not work. Could you look at it please

ii=101;
dt=0.0001;
t = 0:dt:1000;
dx=0.01; %step size
pi=4.*atan(1);
fik=0.4;
H1=0.5;
H1D=0;
A=0;
AD=0.1;
ADinit=AD;
c1b=0.5;
c2b=1-c1b;
dc=0.001;

for i=1:ii;
x=(i-1)*dx;
        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

c1=c1b+dc;
c2=1-c1;
for i=1:ii;
    x=(i-1)*dx;
        fikness=fik*sin(pi*x);
        u1(i)=(c1-H1D*(x-0.5)+AD/2*(x-0.5)^2)./(H1-0.5*fikness-A*(x-0.5))
        u2(i)=(c2+H1D*(x-0.5)-AD/2*(x-0.5)^2)./(1-H1+0.5*fikness+A*(x-0.5)) 
end

p1(1)=0.5*(1-u1(1)^2);
q1(1)=0;
p2(1)=0.5*(1-u2(1)^2);
q2(1)=0;

for i=2:ii

q1(i)=q1(i-1)-dx*(u1(i-1)-ub1(i-1))/dt
p1(i)=0.5*(1-u1(i)^2)+q1(i)
end 

for i=2:ii;
q2(i)=q2(i-1)-dx*(u2(i-1)-ub2(i-1))/dt
p2(i)=0.5*(1-u2(i)^2)+q2(i)
end

UB1,UB2,U1,U2,P1,P2,Q1,Q2 = 1 * 101,他们都有一个行101列如何访问UB1,UB2,U1,U2全阵列,P1,P2 ,Q1,Q2 ??

ub1,ub2,u1,u2,p1,p2,q1,q2 =1*101, all of them have one row 101 column How can I access the whole arrays of ub1,ub2,u1,u2,p1,p2,q1,q2 ??

推荐答案

在命令提示符将显示哪些没有后跟一个分号所有计算。即使你分配一个数组的一个元素,它会显示整个阵列。

the command prompt will show all calculations which are not followed by a semicolon. even if you are assigning one element of an array, it will show the whole array.

P(1)= 1
这表明所有的p的,不只是第一个元素。把分号在每个赋值语句或计算像

p(1)=1 this shows all of p, not just the first element. put semicolon at the end of each assignment statement or calculation like

P2(I)= 0.5 *(1-U2(I)^ 2)+ Q2(I);

然后在code ++写的结尾

then at the end of the code write

u1
u2

这应该显示的最终载体

这篇关于在循环覆盖值:Matlab的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆