Effacer les filtres
Effacer les filtres

Why do I receive parse error at line 30

2 vues (au cours des 30 derniers jours)
Daniel Pitigala
Daniel Pitigala le 13 Sep 2023
Commenté : Dyuman Joshi le 13 Sep 2023
Hello everyone
I'm doing a code for a kalman filter in a mobile robot but i'm not sure as to why i'm getting a parse error at the delta u matrix in line 30 . I have been trying to figure out the error for a while now but no luck. could any one help me?.any help would appreciated
cheers
Daniel
V=0.1;
alpha=0.2;
theta=0:pi/30:pi/4;
K=0:30;
r1=sqrt((x-x1).^2+(y-y1.^2));
r2=sqrt((x-x2).^2+(y-y2.^2));
beta_1=alpha-arcsin(d.*sin(alpha)/sqrt((x-x1)^2+(y-y1)^2));
beta_2=alpha-arcsin(d.*sin(alpha)/sqrt((x-x2)^2+(y-y2)^2));
sigma_v_squared=0.0025;
sigma_a_squared= 0.0036;
sigma_r_sqaured=0.000001;
sigma_beta_squared=0.0000726;
dt=0.05;
P(0)=[0 0 0;0 0 0;0 0 0];
x1=3;
y1=4;
x2=4;
y2=4;
d=1.634;
x_pos=x(K)+(V.*sin(alpha).*cos(theta))/cos(alpha);
Y_pos=Y(K)+(V.*sin(theta));
theta_pos=theta(K)+(V.*tan(alpha)/d);
h_x=[((x-x1)/r1) ((y-y1)/r1) 0 (d.*sin(alpha).*(x-x1))/(r1^2.*sqrt(-(d.*sin(alpha)).^2+(y-y1).^2+(x-x1).^2)) (d.*sin(alpha).*(y-y1))/(r1^2.*sqrt(-(d.*sin(alpha)).^2+(y-y1).^2+(x-x1).^2)) 0; ((x-x2)/r2) ((y-y2)/r2) 0 (d.*sin(alpha).*(x-x2))/(r2^2.*sqrt(-(d.*sin(alpha)).^2+(y-y1).^2+(x-x1).^2)) (d.*sin(alpha).*(y-y2))/(r2^2.*sqrt(-(d.*sin(alpha)).^2+(y-y1).^2+(x-x1).^2)) 0];
delta_x=[1 0 -(V.*sin(theta).*sin(alpha).*dt/cos(alpha)); 0 1 (V.*cos(theta).*dt); 0 0 1];
delta_u=[((sin(alpha).*cos(theta).*dt)/cos(alpha)) (V.*cos(theta).*dt/cos.^2(alpha)) (-V.*sin(theta).*sin(alpha).*dt/cos(alpha)) ; (sin(theta).*dt) 0 (V.*cos(theta).*dt) ; (tan(alpha).*dt/d) (sec^2(alpha).*dt/d) 0];
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
input_error= [sigma_v_squared 0 ; 0 sigma_a_squared];
measurement_error=(sigma_r_squared).*[1 0 0 ;0 1 0 ;0 0 1].*(sigma_beta_squared).*[1 0 0; 0 1 0; 0 0 1];
%% state covariance matrix
estimated_system_uncertanity=(delta_x.*P(0).*delta_x')+(delta_u.*input_error.*delta_u');
%% Kalman gain matrix
S(K+1)=(h_x.*estimated_system_uncertanity.*h_x')+measurement_error;
Kalman_gain= (estimated_system_uncertanity*h_x'.*S(K+1).^-1);
%% update
innovation=measdat7-lambda_e.*Kalman_gain;
x_pos_updated=x_pos+Kalman_gain.*innovation;
Identity=[1 0 0; 0 1 0; 0 0 1];
updated_system_uncertanity=(Identity-Kalman_gain.*h_x).*estimated_system_uncertanity;

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 13 Sep 2023
You get the error because, you have used incorrect syntax for squaring trignometric terms for defining delta_u.
The correct syntax is
cos(input).^2
%or if you want to use an extra set of parenthesis
(cos(input)).^2
You have not defined the variable x in your code above, thus we can not run your code and check for other errors.
However, off a quick glance, I spotted a few errors -
> You need to define the variables - x1, y1, x2, and y2 before using them.
> This code snippet is not valid for 2 reasons
P(0)=[0 0 0;0 0 0;0 0 0];
1st - Indexing in MATLAB starts with 1.
2nd - You can not allot more elements than the number of indices for numeric arrays. Assigning numeric values follows one-to-one correspondance.
Based on the use of this line of code, just use -
P = zeros(3);
%or
P0 = zeros(3);
You can name the variable anything which is accepted by MATLAB - https://in.mathworks.com/help/matlab/matlab_prog/variable-names.html
  2 commentaires
Daniel Pitigala
Daniel Pitigala le 13 Sep 2023
Hi Dyuman Joshi
Thankyou for your help i didn't know that the answer was simple. I'm still relatively new to MATLAB and a bit rusty on the basics. I'll ask again if i run into more issues that i can't figure out .
cheers
Daniel
Dyuman Joshi
Dyuman Joshi le 13 Sep 2023
"I'm still relatively new to MATLAB and a bit rusty on the basics."
I would suggest you to take the free MATLAB Onramp tutorial to learn the essentials of MATLAB.
"I'll ask again if i run into more issues that i can't figure out. "
You are most welcome to.
Is the code running properly now?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by