Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

matlab:why am i getting this error?nvalid expression. When calling a function or indexing a variable, use parentheses

Error:Line: 23 Column: 376 Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.

clc;

Ti=300;

Mi=input('please enter Mi>1 :   ');

thetas=input('please enter mach angle<thetas<90 :   ');

dtheta=(1/10)*(thetas);

gama=1.4;

Ts=(Ti)*(1+(((gama*2)/(gama+1))*(((Mi)^2)*((sin(thetas))^2)-1))*(((gama+1)*(((Mi)^2)*((sin(thetas))^2)))/(2+((gama-1)*(((Mi)^2)*((sin(thetas))^2))))));

delta=atan(2*cot(thetas)*(((((Mi)^2)*((sin(thetas))^2))-1)/((((Mi)^2)*(gama+cos(thetas)))+2)));

Ms=(((sin(thetas-delta))^2)*((1+((gama-1)/2)*((Mi)^2)*((sin(thetas))^2)))/((gama)*((Mi)^2)*((sin(thetas))^2)-((gama-1)/2)))^(1/2);

vp=0:dtheta:thetas;

vpr=0:dtheta:thetas;

vpt=0:dtheta:thetas;

vp(1,1)=(2/((gama-1)*((Ms)^2)));

vpr(1,1)=vp(1,1)*cos(thetas-delta);

vpt(1,1)=vp(1,1)*sin(thetas-delta);

vpr(1,2)=(vpt(1,1)*dtheta)+vpr(1,1);

M=0:dtheta:thetas;

i=2;


while vpt(1,i)>0.001

    i=i+1;

   eq = (((gama-1)/2)*(1-(vpr(1,i)^2)-(((vpr(1,i)-vpr(1,i-1))/(dtheta))^2))*((2*vpr(1,i))+(((vpr(1,i)-vpr(1,i-1))/(dtheta))*cot(thetas+(i-2)*dtheta))+((vpr(1,i)-(2*vpr(1,i-1))+vpr(1,i-2))/((dtheta)^2))))-(((vpr(1,i)-vpr(1,i-1))/(dtheta))*(((vpr(1,i))*((vpr(1,i)-vpr(1,i-1))/(dtheta)))+(((vpr(1,i)-vpr(1,i-1))/(dtheta))*((vpr(1,i)-(2*vpr(1,i-1))+vpr(1,i-2))/((dtheta)^2)))== 0;

   M(1,i-2)=solve(eq , vpr(1,i));

   vpt(1,i)=((vpr(1,i)-vpr(1,i-1))/(dtheta));

end
question from:https://stackoverflow.com/questions/66065302/matlabwhy-am-i-getting-this-errornvalid-expression-when-calling-a-function-or

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you have such long equations it's better to divide a few parts in variables. I have no idea, what you want to calculate but it's better to leave a space at least between each operand. If your line becomes too long just do a line break with three dots .... I'm also sure, you can eliminate a few unnecessary brackets. Your code works if you just add 2 closing brackets before == 0

eq =    (((gama - 1)/2) * (1 - (vpr(1,i) ^ 2) - ...
        (((vpr(1,i) - vpr(1,i - 1))/(dtheta)) ^ 2)) * ...
        ((2 * vpr(1,i)) + (((vpr(1,i) - vpr(1,i - 1)) / ...
        (dtheta)) * cot(thetas + (i - 2)*dtheta)) + ...
        ((vpr(1,i) - (2 * vpr(1,i - 1)) + vpr(1,i - 2)) /  ...
        ((dtheta) ^ 2)))) - (((vpr(1,i) - vpr(1,i - 1)) / ...
        (dtheta)) * (((vpr(1,i)) * ((vpr(1,i) - vpr(1,i - 1)) / ...
        (dtheta))) + (((vpr(1,i) - vpr(1,i - 1))/(dtheta)) * ...
        ((vpr(1,i) - (2*vpr(1,i - 1)) + vpr(1,i-2)) / ((dtheta)^2))))) == 0;

Still not sure, if your result is correct. At least there's no occuring array about missing parenthesis


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...