MATLAB: How to write a mathematical function in Matlab

cell arrayfunction

Can I build an equation which have different components?
variables written in cell array(1×3) such as 'X1' 'X2' 'X3'
exponents written in matrix (3×3 double) e.g [0 .5 -.5; .5 -.5 0; 1 0 .5]
Parameters written in matrix(3×1) e.g [.55;.25;.6893]
can I get equation like
F= .55*X2^.5*X3^-.5+ .25*X1^.5*X2^-.5+.6893*X1^1*X3^.5
Many thanks

Best Answer

MATLAB is a general purpose programming language. You can build up any string you want.
subf = sprintf('*X%d^e%d', [1:3; 1:3]);
formula = ['a1' subf '+a2' subf '+a3' subf];
What you should try to avoid is executing such strings. Dynamic generation of code is error prone.
Related Question