Cross products with anonymous functions
1 view (last 30 days)
Jonathan Rabe on 23 Sep 2019
I please need help with my code. I want to end up with a matrix. I have an anonymous function which I would like to pass various values (in a vector form) and then I want the outputs in a matrix form.
n = 4;
A = @(th) [-R.*cos(th),-R.*sin(th), 0];
theta = 0:pi/2:2*pi;
Lets say I have values for theta of 0:pi/n:2*pi; When I evaluate the function I get this:
u = 1×9
-0.0500 -0.0250 0.0250 0.0500 0 -0.0433 -0.0433 -0.0000 0
I understand that the vector has the answer vectors next to each other, but where are the intermediate 0's? I would expect the answer to have atleast 12 values.
This is so that I could cross product it with other matrices later on.
Any help would be much appreciated!
Anton Gribovskiy on 23 Sep 2019
If you sure that your th will always be 1-by-n vector, you just need to put semicolons instead of comas for vertical cat:
A = @(th) [-R.*cos(th);-R.*sin(th); zeros(1, length(th))];
Or, if you want to make it working for vertical and horizontal vectors
A = @(th) [-R.*cos(th(:).');-R.*sin(th(:).'); zeros(1, length(th))];