Borrar filtros
Borrar filtros

Error with code?

1 visualización (últimos 30 días)
MOHAMED NOORUL ASRAR
MOHAMED NOORUL ASRAR el 16 de Nov. de 2018
Respondida: Zohaib Ikram el 28 de Abr. de 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 comentario
Torsten
Torsten el 16 de Nov. de 2018
Your parentheses in the expression to define C don't match.

Iniciar sesión para comentar.

Respuestas (3)

madhan ravi
madhan ravi el 16 de Nov. de 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 el 16 de Nov. de 2018
Editada: KSSV el 16 de Nov. de 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 comentario
MOHAMED NOORUL ASRAR
MOHAMED NOORUL ASRAR el 16 de Nov. de 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.

Iniciar sesión para comentar.


Zohaib Ikram
Zohaib Ikram el 28 de Abr. de 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 ???

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by