Reputation: 31
So here's the problem I'm having trouble with.
You solve for an expression using the symbolic engine, but it's parametrized by some z. Now you want to create a function for this expression with variable z.
Here's the code:
syms a1 a2 a4 b1 b2 b4 c1 c2 c4
[a1, a2, a4, b1, b2, b4, c1, c2, c4] = ...
solve('a1 + a4 = 1', ...
'a1*a4 - a2^2 = 0', ...
'b1 + b4 = 7', ...
'b1*b4 - b2^2 = 10', ...
'c1*c4 - c2^2 = 55/4', ...
'c1 + c4 = 8', ...
'c1 = a1 + b1', ...
'c2 = a2 + b2', ...
'c4 = a4 + b4');
Now I can do something like
a1 = @(z) 13/18 - (- (35*z^2)/81 + (280*z)/81 - 1925/324)^(1/2)/2 - z/18;
to define a1 to be the first entry of the vector a1 that was already defined...
But I want to instead to something like
a1 = @(z) a1(1)
and then be able to type a1(2) or a1(4) to plug in values for z into that expression.
How can I do this?
Upvotes: 0
Views: 125
Reputation: 31
Ah, just browsing around stack exchange for related questions and the tweaked some code to find a solution:
f = @(t) subs(a1(1), 'z', t).
Upvotes: 1