Effacer les filtres
Effacer les filtres

Error with code?

1 vue (au cours des 30 derniers jours)
MOHAMED NOORUL ASRAR
MOHAMED NOORUL ASRAR le 16 Nov 2018
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 commentaire
Torsten
Torsten le 16 Nov 2018
Your parentheses in the expression to define C don't match.

Connectez-vous pour commenter.

Réponses (3)

madhan ravi
madhan ravi le 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 le 16 Nov 2018
Modifié(e) : KSSV le 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 commentaire
MOHAMED NOORUL ASRAR
MOHAMED NOORUL ASRAR le 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.

Connectez-vous pour commenter.


Zohaib Ikram
Zohaib Ikram le 28 Avr 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 ???

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by