syms f (x,y) Assign a mathematical expression to f. You can declare these symbolic variables as Simscape language variables, parameters, inputs, or outputs, depending on their physical function and your intended block design. Creating f automatically creates x and y. Make sure the declaration section of the component file contains all the symbolic variables used in these equations. Create a symbolic function f with variables x and y by using syms. However, I'm not aware of such a capability in MATLAB using the symbolic toolbox. The Symbolic Math Toolbox currently does not support composite symbolic functions, or symbolic functions that are functions of another symbolic functions. Now coming to what you wanted to do, it is possible in Mathematica to hold certain expressions unevaluated and massage it to get it in the final output form that you want. The definition for the above function is syms f x a b = ![]() ![]() But my problem involves a vector x with dimension N that is impossible to write down each element explicitly. For the above case, it is easy to get the value of f, e.g. The closest equivalent of this in MATLAB is called an anonymous function. The other problem is on evaluating the function. For e.g., the pure function definition of a derivative w.r.t. With pure functions, the definition is independent of the actual function and if you chuck in any argument, it should evaluate it. Mathematica behaves exactly the same: MATLAB: syms f x When you initialize f to be a symbolic variable, there is no definition associated with f and hence a derivative w.r.t x should return 0 and a derivative w.r.t. This is not an abnormal behaviour, rather the expected one. This doesn't work, because MATLAB evaluates diff(f,x)=diff(f,y)=0 (it doesn't know if it is a function).
0 Comments
Leave a Reply. |