Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Define symbolic function by calling another vector with embedded symbol

3 views (last 30 days)
I need to define a symbolic function but am embedding the symbol in a separate matrix. As a result, when I try to define the new function, I am not explicitly calling the symbol in the code. I get the following message:
"Error using sym/subsindex (line 796) Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'."
Specifically, what I want to do is define hh1_zz below as a symbolic function. Here is the code you would need to understand what I want to do:
All parameters that are not "symbols" are numeric values defined in earlier parts of the code:
syms zz_u zv_u zb_u vz_u vv_u vb_u bz_u bv_u bb_u zz_l zv_l zb_l vz_l vv_l vb_l bz_l bv_l bb_l
tau_u = [t(zz_u, Y1(1,1), Y2(1,1), gamma(i)/G1(1,1), gamma(i)/G2(1,1)), t(zv_u, Y1(1,2), Y2(1,2), gamma(i)/G1(1,2), gamma(i)/G2(1,2)), t(zb_u, Y1(1,3), Y2(1,3), gamma(i)/G1(1,3), gamma(i)/G2(1,3));
t(vz_u, Y1(2,1), Y2(2,1), gamma(i)/G1(2,1), gamma(i)/G2(2,1)), t(vv_u, Y1(2,2), Y2(2,2), gamma(i)/G1(2,2), gamma(i)/G2(2,2)), t(vb_u, Y1(2,3), Y2(2,3), gamma(i)/G1(2,3), gamma(i)/G2(2,3));
t(bz_u, Y1(3,1), Y2(3,1), gamma(i)/G1(3,1), gamma(i)/G2(3,1)), t(bv_u, Y1(3,2), Y2(3,2), gamma(i)/G1(3,2), gamma(i)/G2(3,2)), t(bb_u, Y1(3,3), Y2(3,3), gamma(i)/G1(3,3), gamma(i)/G2(3,3))];
tau_l = [t(zz_l, Y1(1,1), Y2(1,1), gamma(i)/G1(1,1), gamma(i)/G2(1,1)), t(zv_l, Y1(1,2), Y2(1,2), gamma(i)/G1(1,2), gamma(i)/G2(1,2)), t(zb_l, Y1(1,3), Y2(1,3), gamma(i)/G1(1,3), gamma(i)/G2(1,3));
t(vz_l, Y1(2,1), Y2(2,1), gamma(i)/G1(2,1), gamma(i)/G2(2,1)), t(vv_l, Y1(2,2), Y2(2,2), gamma(i)/G1(2,2), gamma(i)/G2(2,2)), t(vb_l, Y1(2,3), Y2(2,3), gamma(i)/G1(2,3), gamma(i)/G2(2,3));
t(bz_l, Y1(3,1), Y2(3,1), gamma(i)/G1(3,1), gamma(i)/G2(3,1)), t(bv_l, Y1(3,2), Y2(3,2), gamma(i)/G1(3,2), gamma(i)/G2(3,2)), t(bb_l, Y1(3,3), Y2(3,3), gamma(i)/G1(3,3), gamma(i)/G2(3,3))];
tu1_u = [P(1,1)*u1(tau_u(1,1),Y1(1,1),Y2(1,1),gamma(i)/G1(1,1)), P(1,2)*u1(tau_u(1,2),Y1(1,2),Y2(1,2),gamma(i)/G1(1,2)), P(1,3)*u1(tau_u(1,3),Y1(1,3),Y2(1,3),gamma(i)/G1(1,3)) ;...
P(2,1)*u1(tau_u(2,1),Y1(2,1),Y2(2,1),gamma(i)/G1(2,1)), P(2,2)*u1(tau_u(2,2),Y1(2,2),Y2(2,2),gamma(i)/G1(2,2)), P(2,3)*u1(tau_u(2,3),Y1(2,3),Y2(2,3),gamma(i)/G1(2,3)) ;...
P(3,1)*u1(tau_u(3,1),Y1(3,1),Y2(3,1),gamma(i)/G1(3,1)), P(3,2)*u1(tau_u(3,2),Y1(3,2),Y2(3,2),gamma(i)/G1(3,2)), P(3,3)*u1(tau_u(3,3),Y1(3,3),Y2(3,3),gamma(i)/G1(3,3))];
tu1_l = [P(1,1)*u1(tau_l(1,1),Y1(1,1),Y2(1,1),gamma(i)/G1(1,1)), P(1,2)*u1(tau_l(1,2),Y1(1,2),Y2(1,2),gamma(i)/G1(1,2)), P(1,3)*u1(tau_l(1,3),Y1(1,3),Y2(1,3),gamma(i)/G1(1,3)) ;...
P(2,1)*u1(tau_l(2,1),Y1(2,1),Y2(2,1),gamma(i)/G1(2,1)), P(2,2)*u1(tau_l(2,2),Y1(2,2),Y2(2,2),gamma(i)/G1(2,2)), P(2,3)*u1(tau_l(2,3),Y1(2,3),Y2(2,3),gamma(i)/G1(2,3)) ;...
P(3,1)*u1(tau_l(3,1),Y1(3,1),Y2(3,1),gamma(i)/G1(3,1)), P(3,2)*u1(tau_l(3,2),Y1(3,2),Y2(3,2),gamma(i)/G1(3,2)), P(3,3)*u1(tau_l(3,3),Y1(3,3),Y2(3,3),gamma(i)/G1(3,3))];
tu2_u = [P(1,1)*u2(tau_u(1,1),Y1(1,1),Y2(1,1),gamma(i)/G2(1,1)), P(1,2)*u2(tau_u(1,2),Y1(1,2),Y2(1,2),gamma(i)/G2(1,2)), P(1,3)*u2(tau_u(1,3),Y1(1,3),Y2(1,3),gamma(i)/G2(1,3)) ;...
P(2,1)*u2(tau_u(2,1),Y1(2,1),Y2(2,1),gamma(i)/G2(2,1)), P(2,2)*u2(tau_u(2,2),Y1(2,2),Y2(2,2),gamma(i)/G2(2,2)), P(2,3)*u2(tau_u(2,3),Y1(2,3),Y2(2,3),gamma(i)/G2(2,3)) ;...
P(3,1)*u2(tau_u(3,1),Y1(3,1),Y2(3,1),gamma(i)/G2(3,1)), P(3,2)*u2(tau_u(3,2),Y1(3,2),Y2(3,2),gamma(i)/G2(3,2)), P(3,3)*u2(tau_u(3,3),Y1(3,3),Y2(3,3),gamma(i)/G2(3,3))];
tu2_l = [P(1,1)*u2(tau_l(1,1),Y1(1,1),Y2(1,1),gamma(i)/G2(1,1)), P(1,2)*u2(tau_l(1,2),Y1(1,2),Y2(1,2),gamma(i)/G2(1,2)), P(1,3)*u2(tau_l(1,3),Y1(1,3),Y2(1,3),gamma(i)/G2(1,3)) ;...
P(2,1)*u2(tau_l(2,1),Y1(2,1),Y2(2,1),gamma(i)/G2(2,1)), P(2,2)*u2(tau_l(2,2),Y1(2,2),Y2(2,2),gamma(i)/G2(2,2)), P(2,3)*u2(tau_l(2,3),Y1(2,3),Y2(2,3),gamma(i)/G2(2,3)) ;...
P(3,1)*u2(tau_l(3,1),Y1(3,1),Y2(3,1),gamma(i)/G2(3,1)), P(3,2)*u2(tau_l(3,2),Y1(3,2),Y2(3,2),gamma(i)/G2(3,2)), P(3,3)*u2(tau_l(3,3),Y1(3,3),Y2(3,3),gamma(i)/G2(3,3))];
tu1 = [reshape(tu1_u,[],1); reshape(tu1_l,[],1)];
tu2 = [reshape(tu2_u,[],1); reshape(tu2_l,[],1)];
hh1_zz(zz_u, zv_u, zb_u, vz_u, vv_u, vb_u, bz_u, bv_u, bb_u, zz_l, zv_l, zb_l, vz_l, vv_l, vb_l, bz_l, bv_l, bb_l)...
= u1(tau_u(1,1),Y1(1,1),Y2(1,1),gamma(i)/G1(1,1)) + delta*lzz1*tu1;
The last line calls all of the symbols in vectors tau_u(1,1) and tu1 but is where the error prevents me from proceeding.

Answers (1)

Rajesh Balagam
Rajesh Balagam on 3 May 2018
You may find the following MATLAB Answers page helpful:
If not, please include a simple reproduction code.

This question is closed.

Community Treasure Hunt

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

Start Hunting!