Proper way to allow MATLAB to recognize 'f' as a function? Also, how to fix error 'unable to convert expression into double array'?

2 views (last 30 days)
I am trying to write the following code and MATLAB is not recognizing that I want to use 'f' as a function of the inputted variables. I've tried syms f(x,y,z), which seems to help with this issue, however MATLAB then shows the following error: 'Unable to convert expression into double array.'
Here is my following code: (I have excluded the Cd portion)
syms f(x,y)
a(n+1) = (thrust(n+1)./m(n+1)-g.*cosd(theta0)-(Cd(n).*0.5.*rho.*u(n).^2.*Aref)./m(n));

Answers (1)

Walter Roberson
Walter Roberson on 19 Feb 2022
You appear to be implementing a Runge-Kutta method.
Your general approach might be valid... if you had defined f as a specific function. You have several choices:
  1. Use function to create f as a function that accepts three parameters and returns a scalar, removing the syms f(x,y) satement; or
  2. assign an anonymous function to f, removing the syms f(x,y) statement; or
  3. create f as a specific symbolic function by giving a definition for it; or
  4. make this all into a function and have the user pass in f in the form of a handle to a function or in the form of a symbolic function
However, it looks to me as if you are defining rocket equations, and rocket equations should be taking into account velocity and altitude, so that they can properly calculate air resistance, and current mass needs to be taken into account in order to determine acceleration, so I do not think you can get away with passing only three parameters to the function.

Community Treasure Hunt

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

Start Hunting!