Error using symbolic function inside a matlab functions

2 views (last 30 days)
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 Comments
Lorenzo Lunghini
Lorenzo Lunghini on 21 Dec 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

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Dec 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 Comment
Lorenzo Lunghini
Lorenzo Lunghini on 21 Dec 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!

Sign in to comment.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!