Error with code?

12 views (last 30 days)
MOHAMED NOORUL ASRAR
MOHAMED NOORUL ASRAR on 16 Nov 2018
Answered: Zohaib Ikram on 28 Apr 2020
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 Comment
Torsten
Torsten on 16 Nov 2018
Your parentheses in the expression to define C don't match.

Sign in to comment.

Answers (3)

madhan ravi
madhan ravi on 16 Nov 2018
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 on 16 Nov 2018
Edited: KSSV on 16 Nov 2018
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 Comment
MOHAMED NOORUL ASRAR
MOHAMED NOORUL ASRAR on 16 Nov 2018
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.

Sign in to comment.


Zohaib Ikram
Zohaib Ikram on 28 Apr 2020
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 ???

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!