- Use function to create f as a function that accepts three parameters and returns a scalar, removing the syms f(x,y) satement; or
- assign an anonymous function to f, removing the syms f(x,y) statement; or
- create f as a specific symbolic function by giving a definition for it; or
- 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
Proper way to allow MATLAB to recognize 'f' as a function? Also, how to fix error 'unable to convert expression into double array'?
3 次查看(过去 30 天)
显示 更早的评论
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));
0 个评论
回答(1 个)
Walter Roberson
2022-2-19
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:
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!