Two MATLAB questions about syms
2 views (last 30 days)
Show older comments
I use matlab syms to define a function
where as follows
syms x y [5,1] matrix;
syms z;
f = (y-z*x).'*(y-z*x)
Now, I have two questions:
1. How to expand the expression of f using MATLAB?
It seems that
expand(f)
does not work! and the other functions such as simplify, collect do not work neither. So I want to know how to expand and simplify this expression in a correct way?
2. How to define the function via an output of diff?
I have tried to define a function first as
syms x y w [5,1] matrix;
syms z t;
f = @(x,y,z) (y-z*x).'*(y-z*x);
phi = @(t) f(x+t*w,y,z);
Then I compute the derivative of ϕ using diff:
diff(phi(t),t);
But I don't know how to make the resulted expression as a function of t (so that I can evaluate the expression of )? subs seems not work!
For the moment, I just copy the expression of computed by diff and define it manually. Hoping to get some better way to do it.
Thanks a lot for any comments and suggestions.
0 Comments
Answers (1)
Walter Roberson
on 6 Feb 2023
Edited: Walter Roberson
on 6 Feb 2023
You are using the "matrix" keyword, which treats the names as matrices . In order to "expand" it you would have to convert to individual symbols
syms x y [5,1] matrix;
syms z;
f = (y-z*x).'*(y-z*x)
expanded = symmatrix2sym(f)
But I don't know how to make the resulted expression as a function of t
You cannot do that. You cannot use a symmatrix in a symfun at this time.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!