필터 지우기
필터 지우기

Error with code?

조회 수: 1 (최근 30일)
MOHAMED NOORUL ASRAR
MOHAMED NOORUL ASRAR 2018년 11월 16일
답변: Zohaib Ikram 2020년 4월 28일
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
MOHAMED NOORUL ASRAR 2018년 11월 16일
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