How to define this variable on MATLAB
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Suvansh Arora
2022년 12월 22일
In order to solve this equation with 5 unknows, follow the MATLAB answers article mentioned below:
댓글 수: 3
Steven Lord
2022년 12월 22일
If you are able to specify that, what are you going to do with that variable and your other equations? Knowing how you're planning to use that information can help us offer suggestions for the best way to achieve your ultimate goal.
Steven Lord
2022년 12월 22일
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
2022년 12월 22일
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
Steven Lord
2023년 1월 12일
Can you prove to me that 2.1265555666349343861231037078585 is the exact root of your system? Are you sure it's not 2.12655556663493438612310370785851 or 2.12655556663493438612310370785849 and is only displayed as 2.1265555666349343861231037078585 because vpa approximated it to 31 decimal places?
Is -8.6736e-19 "close enough" to 0 to be considered zero? For most purposes I'd say yes.
If we look at the Wikipedia page giving some examples of orders of magnitude, the closest example to 8.6e-19 is "The probability of matching 20 numbers for 20 in a game of keno is approximately 2.83 × 10−19." That would require you to choose the same set of 20 numbers from 1-80 as the house. That's not very likely at all.
p = 1./nchoosek(80, 20)
Paul
2023년 1월 12일
Unless solve can find an exact answer, any other solution, whether in double precision or variable precision arithmetic, is going to be an approximation. It's just a matter of how accurate that approximation is and what you're willing to accept. I guess I'm saying the same thing as Steven.
참고 항목
카테고리
Help Center 및 File Exchange에서 Special Values에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!