Clear Filters
Clear Filters

How do I multiply a matrix and a column vector of variables ?

2 views (last 30 days)
I have a matrix 'F' (3 * 20 double) and a cell-type 'ans' (20*1) consisting of variables of the form (1,x,y,z,xy,yx,...). The 'ans' is an output of a function called Poly_List that gives us a list of polynomials. I wanted to multiply F and ans to get a system of equations and use that to get the function
f = @(t,y) F * ans
which I will later use to solve ODEs. This gives me the error
Operator '*' is not supported for operands of type 'cell'.
I thought converting it into type double will help. But when I run
var = str2double(ans)
then var is simply consisting of NaN instead of the variables. Can someone please help?

Accepted Answer

Torsten
Torsten on 9 Jul 2022
Edited: Torsten on 9 Jul 2022
Try a combination of str2sym and cell2sym (I don't know the class of "ans" from your description) to convert ans to a symbolic column vector "Ans". Then use
f = matlabFunction(F * Ans)
to convert the matrix-vector-product to a normal function handle.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!