MATLAB Answers

Solving single variable equation where other variables depends on that single variable

1 ビュー (過去 30 日間)
Dhananjay Singh
Dhananjay Singh 2021 年 9 月 10 日
編集済み: Alan Stevens 2021 年 9 月 10 日
Is there a method to solve equations like :
lets say we first define a variable x initial value unknown and we know y = f(x) ; z = f(y) ; p = f(z).
Now the equation to be solved is like 250 = x + y + z where after solving we find x and we need the final value of p.
I have used iteration to solve this but that takes a long time. Any method would be appreciated.
Thanks

採用された回答

Alan Stevens
Alan Stevens 2021 年 9 月 10 日
編集済み: Alan Stevens 2021 年 9 月 10 日
Try using fzero. For example:
f = @(x) x.^2 +1./x; % arbitrary function: replace with your own
y = @(x) f(x);
z = @(x) f(y(x));
p = @(x) f(z(x));
g = @(x) x + y(x) +z(x) - 250;
% Initial guess
x0 = 1;
x = fzero(g, x0);
format long
disp([x, p(x)])
1.0e+04 * 0.000386468834515 5.333363091026294

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by