I have the error "Unexepected Matlab expression", how can I solve it ?

Hi everyone, I'm trying to build a custom block with the following code :
component pelton_turbine
% Ce composant calcule le couple généré par l'eau sur la turbine.
% 🔹 Déclaration des ports
nodes
H = foundation.hydraulic.hydraulic; % Port hydraulique
R = foundation.mechanical.rotational.rotational; % Port mécanique rotatif
end
% 🔹 Déclaration des paramètres
parameters
eta = {0.85, '1'}; % Rendement de la turbine
rho = {1000, 'kg/m^3'}; % Densité de l'eau
r = {0.5, 'm'}; % Rayon moyen de la roue
end
% 🔹 Déclaration des variables internes
variables
T = {0, 'N*m'}; % Couple généré
Q = {0, 'm^3/s'}; % Débit volumique
H_head = {0, 'm'}; % Hauteur d'eau équivalente
end
% 🔹 Bloc des équations
equations
Q == H.q; % Débit entrant dans le port hydraulique
H_head == H.p / (rho * 9.81); % Calcul de la hauteur d'eau équivalente
T == eta * rho * Q * H_head * r; % Formule du couple hydraulique
R.tau == T; % Appliquer le couple sur l’axe mécanique
end
endcomponent
I keep having the same error : Unexepected Matlab expression for the last line ('endcomponent'). I have already checked a lot of sources of error (hidden spaces, checking that the path is good...). Do you have any idea of what might be wrong ?
Thanks in advance,
Nils

 Akzeptierte Antwort

dpb
dpb am 14 Mär. 2025
Bearbeitet: dpb am 14 Mär. 2025
equations
Q == H.q; % Débit entrant dans le port hydraulique
H_head == H.p / (rho * 9.81); % Calcul de la hauteur d'eau équivalente
T == eta * rho * Q * H_head * r; % Formule du couple hydraulique
R.tau == T; % Appliquer le couple sur l’axe mécanique
end
In the above the "==" should be "=" for assignment, not equality...
I don't have Simscape, but I expect the problem with
endcomponent
is that like all other blocks construction in MATLAB, the syntax is just
end
For human documentation purposes you could add the "component" to indicate the block as a comment, of course...
end % component

2 Kommentare

It worked ! Thanks for your precious help.
Glad to help.
It would be agoodthing™ to then accept the Answer if it solved the problem...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simscape Multibody finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2024b

Gefragt:

am 14 Mär. 2025

Kommentiert:

dpb
am 17 Mär. 2025

Community Treasure Hunt

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

Start Hunting!

Translated by