필터 지우기
필터 지우기

Solving 18 equations in iteration until 3 variables within a percent

조회 수: 3 (최근 30일)
RANJITH REDDY KALLURI
RANJITH REDDY KALLURI 2020년 9월 17일
댓글: J. Alex Lee 2020년 9월 18일
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
RANJITH REDDY KALLURI
RANJITH REDDY KALLURI 2020년 9월 18일
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 2020년 9월 18일
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...

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by