Error using symbolic function inside a matlab functions

2 vues (au cours des 30 derniers jours)
Lorenzo Lunghini
Lorenzo Lunghini le 21 Déc 2021
Commenté : Lorenzo Lunghini le 21 Déc 2021
Hi, i'm trying to make a function that calculate symbolic expression and after that it make a surface plot. Doing this:
syms r
alpha(r)=alpha0+pi/(tf)*(t-t0-(r-r0)/vr) %alpha0, tf, t, r0, vr are defined and constant
All work and no errors are given back.
Problems comes out when i wrote the same rows of code inside a matlab function, matlab gives back this error:
"Error using * (line xx) Invalid operand. Variables of type "sym" cannot be combined with other models."
I'm trying to run this code on server because of the quantity of calculation, on server the version of matlab installed is Matlab2018b, when i run the same files on local (matlab2021b) all work as well.
It is possible that from version 2018b to 2021 the methods to perform operations between "sym" and "double" objects are changed?
  2 commentaires
KSSV
KSSV le 21 Déc 2021
Show us the full code with error line number.
Lorenzo Lunghini
Lorenzo Lunghini le 21 Déc 2021
function [x y z] = parkerINT(t)
%% Just to create initial parameters
t0=0; %s
alpha0=pi/200; %rad
r0=6.96e8; %m
vr=3e5; %m/s
tf=11*365*24*3600; %s
T=((27*24+6)*60+36)*60; %s
omega=2*pi/T; %1/s
rf=10; %AU
% conversion to AU
AU=1.495978707*1e11; %m/AU
r0=r0/AU;
vr=vr/AU;
% conversion to yr
yr=365*24*3600; %s/anno
tf=tf/yr;
vr=vr*yr;
omega=omega*yr;
syms r
alpha(r)=alpha0+pi/(tf)*(t-t0-(r-r0)/vr); %First error
theta(r,phi)=pi/2-atan(tan(alpha(r))*sin(phi+omega*(r-r0)/vr-omega*(t-t0))); %Error repeats here
x(r,phi)=r*cos(phi);
y(r,phi)=r*sin(phi);
z(r,phi)=r*cos(theta(r,phi));
end
This is the function, basically calculate 3d components for a fsurf plot

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Déc 2021
You are trying to use a symbolic function in combination with the Control System Toolbox. That is not possible.
In some cases, you can convert the symbolic function to a ratio of two polynomials and then extract the numerator and denominator and build transfer functions. Or sometimes you can convert to state-space representation.
  1 commentaire
Lorenzo Lunghini
Lorenzo Lunghini le 21 Déc 2021
Understood, i've solved this issue making some explicit casting to "sym" variable.
I've converted all the variable using sym fun like:
tf=sym(tf);
It is not fancy but it works.
Thank u!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by