When I make a function call in the command window by making vector argument X by writing Lx(X)which is defined in M file as follows:
function [Lx]= Lx(X) diff(L,X) return
it gives me following error message:
""""""""Undefined function or variable 'L'.
Error in Lx (line 2) diff(L,X)""""""""""
Although I had defined the function L as L=L= x1^2+x2^2+u1^2+u2^2; and X=[x1 x2], in the command window, it is happening. Please help out.Kinda urgent.Please
No products are associated with this question.
You need to have L as an input argument in your function. Functions do not reach into the command window to read variables there. You must provide them as inputs.
And don't name your output variable the same name as your function. The same is true of just working at the command line, you don't want to name variables the same name as functions.
So your function definition should be something like:
function Lprime = Lx(L,X) Lprime = diff(L,X); end
Although I'm not sure why you need a function for that symbolic differentiation, just do it at the command line.
Finally, your syntax:
is not going to work. Read the help for diff()
I told you that your syntax would not work:
"Finally, your syntax:
is not going to work. Read the help for diff()"
You have to be clear on what result you expect here.
syms X L = 2*X; Lx = diff(L,X);
Produces the answer you expect, 2.
Note you must have the Symbolic Toolbox for this symbolic differentiation.
Play games and win prizes!Learn more