Hi, I have the 4 equations mentioned below. I Ca,Cb,Cc are unknown. For a user input of Cd, I want to solve of the rest. The calculated numbers should ideally not be negative.
'Z' can be treated as different under inputs (they are not variables) Equations:
(Z-Z*Ca)/(Z) - Z*Ca*Cb=0
(Z-Z*Cb)/(Z) - (Z*Ca*Cb+Z*Cb*Cc) = 0
(-Z*Cc/Z) + Z*Ca*Cb-Z*Cb*Cc = 0
-Z*Cd/(Z) + Z*Cb*Cc = 0 (Cd is an input by the user too)
Need help with the matlab code

댓글 수: 1

Ameer Hamza
Ameer Hamza 2018년 5월 3일
Your system is Overdetermined, you will not get a solution unless one of the equations is linearly dependent on other equations (highly likely). Do you want a solution in the least square sense as done by @Torsten?

댓글을 달려면 로그인하십시오.

 채택된 답변

Torsten
Torsten 2018년 5월 3일

0 개 추천

Cd=...;
Z=...;
fun=@(x)[1-x(1)-Z*x(1)*x(2);1-x(2)-Z*x(2)*(x(1)+x(3));-x(3)+Z*x(2)*(x(1)-x(3));-Cd+Z*x(2)*x(3)];
lb=[0 0 0];
ub=[Inf Inf Inf];
x0=[1 1 1];
x = lsqnonlin(fun,x0,lb,ub);
Ca = x(1)
Cb = x(2)
Cc = x(3)
Best wishes
Torsten.

댓글 수: 2

I just listed your four equations here where I set Ca=x(1), Cb=x(2) and Cc=x(3).
E.g.
(Z-Z*Ca)/(Z) - Z*Ca*Cb=0
-> 1-Ca-Z*Ca*Cb=0
-> 1-x(1)-Z*x(1)*x(2)=0
It should be easy for you to alter the line if the Z's are different.
Best wishes
Torsten.
Remston Martis
Remston Martis 2018년 5월 3일
yes i read it wrong.. works perfectly. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Computations에 대해 자세히 알아보기

태그

질문:

2018년 5월 3일

댓글:

2018년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by