Hi, how do I fix the error using superiorfloat? I've tried using double() for the subs() like I've seen suggested before but that caused an error.

31 views (last 30 days)
syms thetadot(t) theta(t) theta_ff(t) thetadot_ff(t)
NOFFEOM=subs(unknowns.thetaddot,[{'theta'},{'thetadot'}],[{theta},{thetadot}]);
FFEOM=subs(unknowns1.thetaddot,[{'theta'},{'thetadot'}],[{theta},{thetadot}]);
eomFunc=odeFunction([thetadot,NOFFEOM],[theta,thetadot],mu,R,m,k);
eomFunc2=odeFunction([thetadot,FFEOM],[theta,thetadot],mu,R,m,k);
%Error appears in line below:
[t,thet]=ode45(@(t,thet)eomFunc(t,thet,mu,R,m,k),0:1,[pi/2,0]);
plot(t,thet)
xlabel('Time')
ylabel('Angle')
ERROR:
Error using superiorfloat
Inputs must be floats, namely single or double.

Accepted Answer

Walter Roberson
Walter Roberson on 22 Nov 2024 at 23:42
Edited: Walter Roberson on 23 Nov 2024 at 1:16
eomFunc=odeFunction([thetadot,NOFFEOM],[theta,thetadot],mu,R,m,k);
The syntax of odeFunction requires that the third parameter unwards must be symbolic variables. From the fact that odeFunction worked we know that mu R m and k must be symbolic variables.
[t,thet]=ode45(@(t,thet)eomFunc(t,thet,mu,R,m,k),0:1,[pi/2,0]);
The @(t,thet)eomFunc(t,thet,mu,R,m,k) part creates the handle to an anonymous function that accepts two parameters, and passes each of those two parameters to eomFunc. The function handle also captures the current values of mu R m and k and passes them as well to oemFunc
But we have seen above that mu R m and k are symbolic variables. So you are passing symbolic variables to eomFunc . Unless eomFunc happens to ignore those variables, you are going to get symbolic results from eomFunc which is a problem for ode45. The returns from the objective function of ode45 must be strictly single or double.
  2 Comments
Amanda
Amanda on 23 Nov 2024 at 0:19
Thank you for your help! How do you suggest fixing this? If I try to take out the symbolic variable R, mu, m, and k, it says that there are not enough input arguments. I've never used this function before so I'm not sure how to correct this.
Walter Roberson
Walter Roberson on 23 Nov 2024 at 1:21
You need to assign numeric mu, R, m, k values before the line that constructs the anonymous function.
ode45() works with strictly numeric values. You can pass in symbolic variables or symbolic expressions as part of the extra parameters (beyond the first two parameters), but the code of the function has to either ignore those symbolic expressions or else eventually turn the results of the computations into single() or double() values. It is seldom worth the bother of passing symbolic variables or symbolic expressions as extra parameters into ode45()

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!