# How to define this variable on MATLAB

8 views (last 30 days)

Show older comments

I have this positive equilibrium (x,l,y,v,M) where

x = (q/b)*(eta+(eps*M)/(1+M))*(1+mu+((rho*M)/(1+M)))

l = (q/(alp*sig))*(zeta*M-omega0)

y = (1/sig)*(zeta*M-omega0)

v = (b/sig)*(1/(eta+(eps*M)/(1+M)))*(zeta*M-omega0)

M is a positive root of the following equation

r0*(1+k1*(mu+(rho*M)/(1+M))*(1-k2*(mu+(rho*M)/(1+M))))*(eta+(eps*M)/(1+M))*(K-alp*sig*q*(eta+(eps*M)/(1+M))*(1+mu+(rho*M)/(1+M))-b*(q+alp)*(zeta*M-omega0))-b^2*alp*K*(zeta*M-omega0)=0

Does anyone have an idea of how to enter these informaion on MATLAB, espically the last three lines?

##### 0 Comments

### Answers (2)

Suvansh Arora
on 22 Dec 2022

In order to solve this equation with 5 unknows, follow the MATLAB answers article mentioned below:

##### 3 Comments

Steven Lord
on 22 Dec 2022

If you want to assign a sym object into an array and operate symbolically, preallocate the array as a sym array rather than as a double. If you then wanted to pass that into a function that only accepts double arrays you may need to convert at that point (which may involve using subs to substitute values for the symbolic variables.)

A = zeros(3, 4, 'sym')

syms x

A(2, 2) = x^2 % this works

Compare with:

B = zeros(3, 4)

B(2, 2) = x^2 % this throws an error

Paul
on 22 Dec 2022

Hi @Yakoob

We can use the Symbolic Math Toolbox as one option

Set up the equations

r0=0.05;

k1=0.5;

mu=0.5;

rho=0.5;

k2=0.5;

eta=0.05;

eps=0.25;

K=1;

alp=0.1;

sig=0.05;

q=0.5;

b=0.1;

zeta=4;

omega0=1;

syms M positive

x = (q/b)*(eta+(eps*M)/(1+M))*(1+mu+((rho*M)/(1+M)));

l = (q/(alp*sig))*(zeta*M-omega0);

y = (1/sig)*(zeta*M-omega0);

v = (b/sig)*(1/(eta+(eps*M)/(1+M)))*(zeta*M-omega0);

eqn = r0*(1+k1*(mu+(rho*M)/(1+M))*(1-k2*(mu+(rho*M)/(1+M))))*(eta+(eps*M)/(1+M))*(K-alp*sig*q*(eta+(eps*M)/(1+M))*(1+mu+(rho*M)/(1+M))-b*(q+alp)*(zeta*M-omega0))-b^2*alp*K*(zeta*M-omega0)==0

eqn = simplify(lhs(eqn)) == 0

Try solve

Msol1 = solve(eqn,M)

Use vpa to get the root of the polynomial

vpa(Msol1)

Verify the solution

subs(lhs(eqn),M,vpa(Msol1))

Alternatively, we can extract the numerator of the LHS and use roots, there is only ony positive solution:

Msol2 = roots(sym2poly(numden(lhs(eqn))))

If the equation to solve was more complicated then just a sixth order polynmial, we could use vpasolve

Msol3 = vpasolve(eqn,M,[0 inf])

Or if desired to just get a numerical solutiion, use fsolve. The function to solve could have been defined directly without going through the symbolic stuff, but since we already have the symbolic stuff, just use it

fun = matlabFunction(lhs(eqn));

Msol4 = fsolve(fun,1)

fun(Msol4)

##### 6 Comments

Paul
on 12 Jan 2023

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!