Using arrayfun and fsolve together
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, hope you're doing well. With the help of Darova from the forum, I have been able to formulate this code which essentially solves my system of equations (Equations_G1_G2) for two unknowns; Phi and qRj. An issue arises with regards mj (Line 4). When mj is a scalar, the code works as required and there are no qualms, however, I would like to input mj as a matrix; as shown, and have fsolve iterate through each element in the mj array. How would I go about doing this? I was thinking about using arrayfun but I don't know how to combine arrayfun and fsolve in this manner.
In effect, I would like Phi_qRj (Line 14) to solve my system equations for each element in array mj and then return two arrays for Phi and qRj. So I would have a value of Phi and qRj for each mj values
I appreciate any help!
function IAST
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INPUTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global mj Lj qAC K n C0i Phi qRj
mj = [1,2,3,4,5]; % PROBLEM
Lj = 0.1;
qAC = mj./Lj
K = [49.1103, 69.49];
n = [0.2095, 0.19727];
C0i = [1,1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SOLVE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
opt = optimset('display','on');
x0 = ones(1,2);
Phi_qRj = fsolve(@(x)G1_G2(x),x0,opt); % SOLVE EQUATION
Phi = Phi_qRj(:,1)
qRj = Phi_qRj(:,2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Equations_G1_G2 = G1_G2(x)
global mj Lj qAC K n C0i Phi qRj
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% EQUATIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Phi = x(1);
qRj = x(2);
Z1 = ((Phi*n)./K).^(1./n)
Z2 = (qRj * qAC);
Z3 = C0i./(Z1+Z2);
Z4 = C0i./(Z1+Z2).*(1./n);
G1 = sum(Z3) + -1;
G2 = sum(Z4) + -(Phi/qRj);
Equations_G1_G2 = [G1 G2]';
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Systems of Nonlinear Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!