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

3 visualizaciones (últimos 30 días)
Nils
Nils el 14 de Mzo. de 2025
Comentada: dpb el 17 de Mzo. de 2025
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

Respuesta aceptada

dpb
dpb el 14 de Mzo. de 2025
Editada: dpb el 14 de Mzo. de 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 comentarios
Nils
Nils el 17 de Mzo. de 2025
It worked ! Thanks for your precious help.
dpb
dpb el 17 de Mzo. de 2025
Glad to help.
It would be agoodthing™ to then accept the Answer if it solved the problem...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Troubleshooting en Help Center y File Exchange.

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by