How to solve this nonlinear simultaneous equation?

%For C1
lambda1 = [60.21, 41.58, 9.11, 8.71, 3.83, 3.74, 18.06]
r1 = poissrnd(lambda1)
%For C2
lambda2 = [41.58, 60.21, 8.71, 9.11, 3.74, 3.83, 18.06]
r2 = poissrnd(lambda2)
%Designed training sequences x1 and x2
x1 = [1,1,1,0,0,0,0,1,0,1,0,1,1,0,0,1] ;
x2 = [1,1,1,0,1,0,0,0,1,1,1,0,0,0,0,1] ;
%X[3] to X[16]
X3 = [1 1 1 1 1 1 1]' ;
X4 = [0 0 1 1 1 1 1]' ;
X5 = [0 1 0 0 1 1 1]' ;
X6 = [0 0 0 1 0 0 1]' ;
X7 = [0 0 0 0 0 1 1]' ;
X8 = [1 0 0 0 0 0 1]' ;
X9 = [0 1 1 0 0 0 1]' ;
X10 = [1 1 0 1 1 0 1]' ;
X11 = [0 1 1 1 0 1 1]' ;
X12 = [1 0 0 1 1 1 1]' ;
X13 = [1 0 1 0 0 1 1]' ;
X14 = [0 0 1 0 1 0 1]' ;
X15 = [0 0 0 0 1 0 1]' ;
X16 = [1 1 0 0 0 0 1]' ;
%X,a 7x14 matrix
X = [X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14,X15,X16];
%C, a 7x2 matrix
C = [r1; r2]' ;
%Y, a 14x2 matrix
Y = X'*C ;
%Yd = Poiss(Y) (at equation (8))
Yd = poissrnd(Y)
%y1, a 14x1 matrix ; y2, a 14x1 matrix
y1 = Y(:,1)
y2 = Y(:,2)
%Least Square Estimate of C
Cls = (inv(X*X'))*(X*Yd)
% To set to zero all the negative entries of C
Cls1 = max(Cls,0)
%Mean square error of LS C and C
MSE = mean((C - Cls1).^2)
syms C1 C2 C3 C4 C5 C6 C7
(((y1(1))/(C1 + C2 + C3 + C4 + C5 + C6 + C7))*X3) + (((y1(2))/C3 + C4 + C5 + C6)*X4) + ...
(((y1(3))/C2 + C5 + C6 + C7)*X5) + (((y1(4))/C4 + C7)*X6) + (((y1(5))/C6 + C7)*X7) + ...
(((y1(6))/C1 + C7)*X8) + (((y1(7))/C2 + C3 + C7)*X9) + (((y1(8))/C1 + C2 + C4 + C5 + C7)*X10) + ...
(((y1(9))/C2 + C3 + C4 + C6 + C7)*X11) + (((y1(10))/C1 + C4 + C5 + C6 + C7)*X12) + ...
(((y1(11))/C1 + C3 + C6 + C7)*X13) + (((y1(12))/C3 + C5 + C7)*X14) + (((y1(13))/C5 + C7)*X15) + ...
(((y1(14))/C1 + C2 + C7)*X16) == (X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + X11 +X12 + X13 + X14 + X15 + X16)

9 Comments

After I type out this equation, 7 equations are formed by Matlab itself, how to compute C1, C2, C2, C4, C5, C6, and C7? What function and code should I use?
2*C2 + C3 + 2*C4 + 2*C5 + 2*C6 + 5*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 507/C1 == 6
2*C2 + 2*C3 + 2*C4 + 2*C5 + 2*C6 + 5*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 258/C1 + 248/C2 == 6
3*C3 + 2*C4 + 2*C5 + 3*C6 + 4*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 86/C1 + 170/C2 + 88/C3 == 6
C2 + C3 + 4*C4 + 3*C5 + 3*C6 + 4*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 225/C1 + 89/C2 + 48/C3 + 29/C4 == 6
C2 + 3*C4 + 5*C5 + 3*C6 + 5*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 225/C1 + 78/C2 + 88/C3 + 29/C5 == 7
2*C3 + 3*C4 + 3*C5 + 5*C6 + 5*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 175/C1 + 167/C2 + 48/C3 + 23/C6 == 7
2*C2 + 3*C3 + 4*C4 + 5*C5 + 5*C6 + 12*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 507/C1 + 248/C2 + 88/C3 + 29/C4 + 29/C5 + 23/C6 == 14
These are the 7 equations form by Matlab when I run the simulation.
Try fsolve or vpasolve
vpasolve C1 C2 C3 C4 C5 C6 C7
Is this how I should call it? Undefined function 'vpasolve' for input arguments of type 'char'. I got this comment after i run it.
And FSOLVE requires the following inputs to be of data type double: 'X0'.
Because my equation will change for every iteration/ every run, and the 7 equations will also changing with every run, I am not sure how should I code it. Please help me thanks.
see the result below:
c1: 4.92311239217309
c2: 10.8503467592613
c3: 27.7213482239995
c4: 1.29922647321007
c5: 0.346881880603912
c6: 0.547555778139712
c7: -32.3832993726449
Feval:
1.11981535155792E-11
-1.37596600779943E-11
1.02069463991938E-11
2.89368529138301E-11
2.29221086556208E-11
6.85744794282073E-11
-2.25526264330256E-11
May I know how do u code to get the C1, C2, C3, C4, C5, C6, and C7?
Hi, rather than Matlab, the above results are obtained by a package of 1stOpt, the total code are given follow, very simple. The biggest difference for 1stOpt and Matlab (fsolve or vpasolve) is the optimization algorithm adoptded. 1stOpt can solve optimization problems (such as equation solving, curve fitting...) without requiring initial start-values provided by users, but the global solving ability is much higher than matlab. Hope Mathwork could improving the ability of fsolve and vpasolve in the next version
Parameter C(7);
Function
2*C2 + C3 + 2*C4 + 2*C5 + 2*C6 + 5*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 507/C1 = 6;
2*C2 + 2*C3 + 2*C4 + 2*C5 + 2*C6 + 5*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 258/C1 + 248/C2 = 6;
3*C3 + 2*C4 + 2*C5 + 3*C6 + 4*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 86/C1 + 170/C2 + 88/C3 = 6;
C2 + C3 + 4*C4 + 3*C5 + 3*C6 + 4*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 225/C1 + 89/C2 + 48/C3 + 29/C4 = 6;
C2 + 3*C4 + 5*C5 + 3*C6 + 5*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 225/C1 + 78/C2 + 88/C3 + 29/C5 = 7;
2*C3 + 3*C4 + 3*C5 + 5*C6 + 5*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 175/C1 + 167/C2 + 48/C3 + 23/C6 = 7;
2*C2 + 3*C3 + 4*C4 + 5*C5 + 5*C6 + 12*C7 + 148/(C1 + C2 + C3 + C4 + C5 + C6 + C7) + 507/C1 + 248/C2 + 88/C3 + 29/C4 + 29/C5 + 23/C6 = 14;

Sign in to comment.

Answers (0)

Categories

Asked:

on 29 May 2020

Commented:

on 30 May 2020

Community Treasure Hunt

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

Start Hunting!