MATLAB: Equation solving to get a function

MATLABsolve

I am trying to solve a set of Laplace equations and get three functions. My code is as
syms l lr lc mu s
syms p2(s,l,lr,lc,mu) p1(s,l,lr,lc,mu) p0(s,l,lr,lc,mu)
eqn0=s*p0==lr*p1+lc*p2;
eqn1=s*p1==2*l*p2-lr*p1-mu*p1;
eqn2=s*p2-1==mu*p1-2*l*p2-lc*p2;
eqn=[eqn0,eqn1,eqn2];
[p0sol, p1sol, p2sol]=solve(eqn, [p0, p1, p2])
I am trying to find the functions p0, p1 and p2.
This produces and error saying "The second argument must be a vector of symbolic variables". I found a bunch of threads about this error but could not relate to this formulation.
How do I get what these functions are?

Best Answer

It is not possible to solve with respect to a function; you can only solve with respect to a variable.
syms l lr lc mu s
syms p0 p1 p2
eqn0 = s*p0 == lr*p1+lc*p2;
eqn1 = s*p1 == 2*l*p2-lr*p1-mu*p1;
eqn2 = s*p2-1 == mu*p1-2*l*p2-lc*p2;
eqn = [eqn0,eqn1,eqn2];
[p0sym, p1sym, p2sym] = solve(eqn, [p0, p1, p2])
p0sol = symfun(p0sym, [s,l,lr,lc,mu]);
p1sol = symfun(p1sym, [s,l,lr,lc,mu]);
p2sol = symfun(p2sym, [s,l,lr,lc,mu]);
Related Question