Invalid Expression. Check for missing or extra characters.
2 views (last 30 days)
Show older comments
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] =
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)
0 Comments
Answers (2)
Voss
on 13 Feb 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
0 Comments
Walter Roberson
on 13 Feb 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
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
0 Comments
See Also
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!