Clear Filters
Clear Filters

Solving 18 equations in iteration until 3 variables within a percent

3 views (last 30 days)
Example: following are the equations needed to be solved for convergence of A & B within 1% ; Initial assumption of A is 0.8, B is 0.375.
Eq 1: A = B/(1-C);
Eq 2: B = (D + E)/(F +G);
Eq 3: C = D*E + F*B;
Eq 4: D = 2*A/B; etc.
I could technically write my code using while loop as below, but the equations i have are actually complex and cannot be solved as i did.
I'm trying to find if there is a better way of doing such iterations with few or little known values and guesses.
P.S. The equations and values in here are just to demonstrate, it might or might not actually converge.
%known values
e = 10; f = 5; g = 1.75
% initial guess
a = 0.8;
b = 0.75;
% Temp variables
a_temp = a;
b_temp = b;
a_conv = 0;
b_conv = 0;
while i = 1:100 % to prevent from staying in loop forever
d = 2*a/b; % eq 4
b = (d + e)/(f + g); %eq 2
c = (d*e) + (f*g); % eq 3
a = b/(1-c); % eq 1
a_conv = ( a - a_conv)/a;
b_conv = (b - b_conv)/b;
if a_conv <0.01 && b_conv<0.01
break
else
a_conv = a;
b_conv = b;
end
end
  3 Comments
RANJITH REDDY KALLURI
RANJITH REDDY KALLURI on 18 Sep 2020
There are no differential equations or functions, so I am not sure if they can be called Picard iterations. Can you help me understand on how to use fsolve ? Thank you
J. Alex Lee
J. Alex Lee on 18 Sep 2020
have you read the docs for fsolve? you first need to set up the equations in residual form, i.e.,
r(1) = A - B/(1-C)
r(2) = B - (D + E)/(F +G);
r(3) = C - (D*E + F*B);
r(4) = D - 2*A/B;
etc.
Then you have a standard root finding problem, just plug into fsolve...

Sign in to comment.

Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!