Invalid Expression. Check for missing or extra characters.

5 vues (au cours des 30 derniers jours)
Bryan Tassin
Bryan Tassin le 13 Fév 2022
When I run this code I keep getting the invalid expression error message. How can I fix this? The error occurs at line 28 and 40.
clc; clear;
tic
n = 360;
r1 = 3.3;
r2 = 0.82;
r6 = 1.85;
rcg3 = 2.12;
th1 = pi/2;
th2 = linspace(0,2*pi,n);
th4 = 0;
th6 = 63*(pi/180);
formulation
th3guess = -1.5;
r3guess = 4.2;
r4guess = 1.2;
r5guess = 2;
m = zeros(n,4);
for i = 1:n
[th3,r3,r4,r5] =
Invalid expression. Check for missing or extra characters.

Error in connector.internal.fevalMatlab

Error in connector.internal.fevalJSON
NR(th1,th2(i),th4,th3guess,th6,r1,r2,r3guess,r4guess,r5guess,r6);
th3guess = th3;
r3guess = r3;
r4guess = r4;
r5guess = r5;
m(i,:) = [th3,r3,r4,r5];
end
function [th3,r3,r4,r5] =
NR(th1,th2,th4,th3guess,th6,r1,r2,r3guess,r4guess,r5guess,r6)

Réponses (2)

Voss
Voss le 13 Fév 2022
Add ellipses (...) to the ends of lines when you want to continue the statement to the next line:
clc; clear;
tic
n = 360;
r1 = 3.3;
r2 = 0.82;
r6 = 1.85;
rcg3 = 2.12;
th1 = pi/2;
th2 = linspace(0,2*pi,n);
th4 = 0;
th6 = 63*(pi/180);
% formulation
th3guess = -1.5;
r3guess = 4.2;
r4guess = 1.2;
r5guess = 2;
m = zeros(n,4);
for i = 1:n
[th3,r3,r4,r5] = ...
NR(th1,th2(i),th4,th3guess,th6,r1,r2,r3guess,r4guess,r5guess,r6);
th3guess = th3;
r3guess = r3;
r4guess = r4;
r5guess = r5;
m(i,:) = [th3,r3,r4,r5];
end
function [th3,r3,r4,r5] = ...
NR(th1,th2,th4,th3guess,th6,r1,r2,r3guess,r4guess,r5guess,r6)
% stuff goes here
th3 = 0;
r3 = 0;
r4 = 0;
r5 = 0;
end

Walter Roberson
Walter Roberson le 13 Fév 2022
clc; clear;
tic
n = 360;
r1 = 3.3;
r2 = 0.82;
r6 = 1.85;
rcg3 = 2.12;
th1 = pi/2;
th2 = linspace(0,2*pi,n);
th4 = 0;
th6 = 63*(pi/180);
formulation
Unrecognized function or variable 'formulation'.
th3guess = -1.5;
r3guess = 4.2;
r4guess = 1.2;
r5guess = 2;
m = zeros(n,4);
for i = 1:n
[th3,r3,r4,r5] = ...
NR(th1,th2(i),th4,th3guess,th6,r1,r2,r3guess,r4guess,r5guess,r6);
th3guess = th3;
r3guess = r3;
r4guess = r4;
r5guess = r5;
m(i,:) = [th3,r3,r4,r5];
end
function [th3,r3,r4,r5] = ...
NR(th1,th2,th4,th3guess,th6,r1,r2,r3guess,r4guess,r5guess,r6)
th3 = rand();
r3 = rand() * 10;
r4 = rand() * 100;
r5 = rand() * 1000;
end

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by