How to solve multiple equations dependent on each other?

5 ビュー (過去 30 日間)
R7 DR
R7 DR 2015 年 1 月 30 日
回答済み: Niels 2015 年 1 月 30 日
Hi
How to code this situation?
I have two equations, which are dependent on each other. Y=2X+5----(1) and X=2Y+5-----(2) The initial value of X=1, then I have to solve these equation repeatedly for 10 times.
Thanks

採用された回答

Niels
Niels 2015 年 1 月 30 日
Since you depend on your previous answers, you can simply loop through the equations and store the answers.
x = ones(1,10); % also contains your initial x
y = ones(1,10); % just to preallocate y as well
for i=1:9 % loop 9 times
y(i) = 2*x(i) + 5; % calculate the y-value
x(i+1) = 2*y(i) + 5; % calculate the 'next' x-value
end
y(10) = 2*x(10) + 5; % finish off by calculating the final y-value
If you only care about the final value, this suffices:
x = 1;
for i=1:9
y = 2*x + 5; % calculate the y-value
x = 2*y + 5; % calculate the 'next' x-value
end
y = 2*x + 5;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by