Solve a system of equations

1 view (last 30 days)
Rustem Devletov
Rustem Devletov on 10 May 2019
Edited: Rustem Devletov on 10 May 2019
Can anyone help me to write a code for solving the following system of equations?
w0=10; k1=3; k2=6; V1=20; V2=30;
x21=(w0+x13)/(w0+x13+k1*V1);
x22=(w0+x13);
x31=x22*x21/(x22+k2*V2);
x32=x22;
x13=x31*x32;
Suppose that x13 has an initial value (any number, let's say it is 1); Then we define what x21, x22, x31, 32 will be equal to and new value of x13*n;
If |x13*n-x|>=e (where e is a small number), then a new value of x13 should be x13*n, and we should solve that system until |x13*n-x13|<e;
Below is my idea, but I know it may be stupid but don't judge too harsh because I'm new to matlab and don't know how to do that.
w0=10; k1=3; k2=6; V1=20; V2=30; x13=1; e=0.00001; n=0.1
while abs(x13*n-x13)>=e
x21=(w0+x13)/(w0+x13+k1*V1);
x22=w0+x13;
x31=x22*x21/(x22+k2*V2);
x32=x22;
x13=x31*x32;
x13=x13*n;
end
It never stops counting
  2 Comments
darova
darova on 10 May 2019
Not allowed to use fsolve()?
Rustem Devletov
Rustem Devletov on 10 May 2019
We can use anything. If you can, show me please how to do that

Sign in to comment.

Accepted Answer

Torsten
Torsten on 10 May 2019
x22 - w0 =
x13 =
x31 * x32 =
x22 * x21 / (x22+k2*V2) * x22 =
x22 * (x22/(x22+k1*V1)) / (x22+k2*V2) * x22
This gives a quadratic equation in x22. Solve it.
Once you have x22, x13 = x22 - w0.
  8 Comments
Torsten
Torsten on 10 May 2019
Then try your fsolve-code. fsolve uses Newton's (iterative) method. But it might converge to the wrong solution because the quadratic equation in x22 usually has two solutions.
Rustem Devletov
Rustem Devletov on 10 May 2019
Edited: Rustem Devletov on 10 May 2019
Can you check it out please?
file 1
global w0 k1 k2 x32
w0=10; k1=3; k2=6; V1=20; V2=30 x13=1; e=0.00001;
k=x13;
x21=(w0+x13)/(w0+x13+k1*V1);
x22=w0+x13;
x31=x22*x21/(x22+k2*V2);
x32=x22;
x13=x31*x32;
while abs(x13-k)>=e
k=x13;
x21=(w0+x13)/(w0+x13+k1*V1);
x22=w0+x13;
x31=x22*x21/(x22+k2*V2);
x32=x22;
x13=x31*x32
end
file 2
function [Q]= myfun(x)
global x32
alpha1=0.5;
alpha2=0.5;
V1=x(1);
V2=x(2);
C1=10; %cost 1
C2=15; %cost 2
C3=24;%cost 3
Q=C1*V1^alpha1+C2*V2*alpha2+C3*x32;
end
file 3 (solution)
clear all
clc
fun = @myfun;
x = [20, 30];
A = [];
b = [];
Aeq = [];
beq = [];
lb = [10, 20];
ub = [30, 40];
nonlcon = [];
options = optimoptions('fmincon');
Cany
[x,fval,exitflag,output] = fmincon(fun,x,A,b,Aeq,beq,lb,ub,nonlcon,options)
I get the following error
Error using fmincon (line 612)
Supplied objective function must return a scalar value.
Error in solution (line 14)
[x,fval,exitflag,output] = fmincon(fun,x,A,b,Aeq,beq,lb,ub,nonlcon,options)

Sign in to comment.

More Answers (0)

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!