Reputation: 69
I'm writing a program that can solve the equation of motion for an inverted pendulum. However, on the line "F=int ... ", I get an error saying "unbalanced or unexpected parenthesis or bracket". However, I checked it many times and it seems that the bracket/parenthesis are balanced. I'm guessing the error is coming from the part "s,tn-(n/2),tn+(n/2)", but I'm not sure why
function [ theta ] = Untitled( theta_o,omega_o )
nt=5001; %since (50-0)/.01 = 5000
dt = .01; % =H
H=.01;
theta_n = ones(nt,1);
theta_n(1)=0; %theta_o
omega_n = ones(1,nt);
omega_n(1)=-0.4; %omega_o
epsilon=10^(-6);
eta = epsilon*10;
t_o=0;
for n=1:4999
tn=t_o+n*dt;
F=int((422.11/eta)*exp[[5*(4*((eta*t-s-tn)^2)/eta^2)-1]^(-1)]*omega, s,tn-(n/2),tn+(n/2))
theta_n(n+1) = theta_n(n) + h*F;
end
end
EDIT: I converted the [] into (), and now the error "Undefined function or variable 't'."
Upvotes: 0
Views: 2516
Reputation: 1215
As @Molly pointed out in her comment the correct line should be:
F=int((422.11/eta)*exp((5*(4*((eta*t-s-tn)^2)/eta^2)-1)^(-1))*omega, s,tn-(n/2),tn+(n/2))
You cannot use square brackets [
and ]
in Matlab like you would use them when writing maths on paper. Use round brackets (
and )
for all brackets in Matlab.
Square brackets are used to denote matrices in Matlab.
EDIT: That error is because in you code you have eta*t
but you have not told MATLAB what t
is. My guess is that it should be either tn
or dt
, or you need to define it as something:
t = %the correct value for t
But, I am not familiar with the problem you are trying to solve, so I suggest checking that you copied down the formula correctly.
Upvotes: 1