Error with code?

3 次查看(过去 30 天)
MOHAMED NOORUL ASRAR
function [ C ] = Q3( x )
% let x1 denote t
% let x2 denote q
C = 13.9 + (58.056*((x(1)).^-0.3017)) + ((11.2657*((x(1)).^0.4925)/((x(2)).*1)) + ((0.4491*((x(1))^0.7952)/((x(2))) + ((0.06719*(2*((x(1))) + 1.2*(x(2))).^0.861)/(x(2))))+0.0450*(2*(x(1))) + 1.2*(x(2))) + 14.002*((x(2)).^-0.1899)+ 0.0002914*(((x(2)).^0.671);
is there an error with the code? Pls answer and correct it for me. This is my m-file for using fminsearch, but I kept on getting these errors
Error: File: Q3.m Line: 4 Column: 258
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});
  1 个评论
Torsten
Torsten 2018-11-16
Your parentheses in the expression to define C don't match.

请先登录,再进行评论。

回答(3 个)

madhan ravi
madhan ravi 2018-11-16
Always break long equation to pieces:
C = 13.9 + 58.056*(x(1).^-0.3017) + ...
(11.2657*(x(1).^(0.4925)))/(x(2).*1) + ...
0.4491*x(1)^(0.7952)/x(2) +...
0.06719*2*x(1) + ...
(1.2*(x(2).^0.861))/(x(2))+0.0450*2*x(1) +...
1.2*x(2) + 14.002*x(2).^(-0.1899)+ 0.0002914*x(2).^(0.671);

KSSV
KSSV 2018-11-16
编辑:KSSV 2018-11-16
YOu for got to add one bracket.Check the below lines.....the braces are added properly.
C = 13.9 + (58.056*((x(1)).^-0.3017)) + .......
((11.2657*((x(1)).^0.4925)/((x(2)).*1))) + ......
((0.4491*((x(1))^0.7952)/((x(2))) + .......
((0.06719*(2*((x(1))) + 1.2*(x(2))).^0.861)/(x(2))))+.......
0.0450*(2*(x(1))) + 1.2*(x(2))) +......
14.002*((x(2)).^-0.1899)+ 0.0002914*(((x(2)).^0.671));
  1 个评论
MOHAMED NOORUL ASRAR
C = 13.9 + (58.056*((x(1)).^-0.3017)) + ((11.2657*((x(1)).^0.4925)/((x(2)).*1))) + ((0.4491*((x(1))^0.7952)/((x(2))) + ((0.06719*(2*((x(1))) + 1.2*(x(2))).^0.861)/(x(2))))+(0.0450*(2*(x(1))) + 1.2*(x(2))))/(x(2)))) + 14.006*((x(2)).^-0.1899)+ 0.0002914*(((x(2)).^0.671));
I edited the part with 0.0450 again. by dividing by x2 and then, it doesnt work now. Can you help me check?
Thanks.

请先登录,再进行评论。


Zohaib Ikram
Zohaib Ikram 2020-4-28
x=linspace(0,2,10);
y=linspace(0,2,10);
z=linspace(0,2,10);
[XX,YY,ZZ]=meshgrid(x,y,z);
Q=1.e-9;
C=9.e9;
r=(x.^2+y.^2+z.^2).^.5;
Ex=Q*C/r.^3*x;
Ey=Q*C/r.^3*y;
Ez=Q*C/r.^3*z;
figure()
quiver3(x,y,z,Ex,Ey,Ez)
view(-35,45)
i found an error when i run this code any one help please ???

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by