error in the matrix

1 次查看(过去 30 天)
hey guys when i try to run the program it tell me excced number of matrix in line 41 i want to draw p in y axis with V in x axis thank you
clc;clear;
B=79.21
a=30.835
L=83.919
j=0
k=0
n=0
f=0
i=0
P_i=6
RPM=300
d_time=(5/360)*(60/RPM)
p(k+1)=.99*(P_i)
p(k+2)=.9*p(1)
T(f+1)=290
R=.287
V(1)=27*1000
c_d=.6
h=8
Tw=290
cp=1.005
m(n+1)=p(1)*V(1)/(R*T(1))
for Theta=0:5:360
i=i+1
j=j+1
x(i)=a*cos(Theta)+sqrt((((L*L)-(a*a)*(sin(Theta))^2)))
V(j)=(pi/4)*(B^2)*(x(i))+(27*1000)
end
for Theta=0:5:360
n=n+1
k=k+1
f=f+1
rho=(p(k)+p(k+1))./(2*R*T(f))
if (Theta <=120)
d_Mi=c_d*(pi/4)*((.3)^2)*sqrt(2*rho.*(p(k)-p(k+1)))
m(n+1)=m(n)+d_Mi
T(f+1)=(d_time*h*pi*B*x(i).*(2*Tw-T(f))-(p(k)+p(k+1)).*(V(j+1)-V(j))+2*m(n)*cp*T(f))./(2*m(n+1).*cp+(d_time*h*pi*B.*x(i)))
p(k+1)=m(n+1).*R*T(f+1)./(v(j+1))
end
if (Theta >=160) && (Theta <=300)
d_Me=c_d*(pi/4)*((.28)^2)*sqrt(2*rho*(p(k)-p(k+1)))
m(n+1)=m(n)-d_Me
T(f+1)=(d_time*h*pi*B*x(i)*(2*Tw-T(f))-(p(k)+p(k+1))*(V(j+1)-V(j))+2*m(n)*cp*T(f))/(2*m(n+1)*cp+(d_time*h*pi*B*x(i)))
p(k+1)=m(n+1)*R*T(f+1)/(v(j+1))
end
if (Theta >=300) && (Theta <=360)
m(n+1)=m(n)
T(f+1)=(d_time*h*pi*B*x(i)*(2*Tw-T(f))-(p(k)+p(k+1))*(V(j+1)-V(j))+2*m(n)*cp*T(f))/(2*m(n+1)*cp+(d_time*h*pi*B*x(i)))
p(k+1)=m(n+1)*R*T(f+1)/(v(j+1))
end
if (Theta >120) && (Theta <160)
m(n+1)=m(n)
T(f+1)=(d_time*h*pi*B*x(i)*(2*Tw-T(f))-(p(k)+p(k+1))*(V(j+1)-V(j))+2*m(n)*cp*T(f))/(2*m(n+1)*cp+(d_time*h*pi*B*x(i)))
p(k+1)=m(n+1)*R*T(f+1)/(v(j+1))
end
end
  1 个评论
Jan
Jan 2018-1-29
Please mark the code and press the "{} Code" button. Currently the code is not readable.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2018-1-29
Your code
j=0
for Theta=0:5:360
i=i+1
j=j+1
x(i)=a*cos(Theta)+sqrt((((L*L)-(a*a)*(sin(Theta))^2)))
V(j)=(pi/4)*(B^2)*(x(i))+(27*1000)
end
will leave j as 73 and V as length 73.
Your line
T(f+1)=(d_time*h*pi*B*x(i).*(2*Tw-T(f))-(p(k)+p(k+1)).*(V(j+1)-V(j))+2*m(n)*cp*T(f))./(2*m(n+1).*cp+(d_time*h*pi*B.*x(i)))
has V(j+1)-V(j) which tries to access V(73+1)-V(73) but V(74) does not exist.
  3 个评论
Walter Roberson
Walter Roberson 2018-1-29
Assign
j = 0;
before
for Theta=0:5:360
and where you have k=k+1 add in j=j+1;
I suspect some of your variables are effectively duplicates of each other.
abdalrhman hassan
abdalrhman hassan 2018-1-29
yes it should be try and error but i didn’t finsh yet i should use while loop but i can’t seem to remember how it work,thank you so much

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by