MATLAB Answers

# How to solve equations that use other equations?

3 ビュー (過去 30 日間)
Simrat Singh 2016 年 6 月 3 日
Answered: David 2016 年 7 月 27 日
I am trying to solve an equation whose variables are equations. Because of the complexity of the setup, I cannot enter the final equation that I want to solve in fsolve and am having to use intermediate variables to represent smaller equations. I am attaching a small code which mimics what I am trying to do but on a smaller scale.
y = symfun(sin(x)+cos(x), x);
z = symfun(-sin(y)+cos(x), [x,y]);
m = symfun(y-z, x);
x = fzero(@(x) m(x), 1);

#### 0 件のコメント

サインイン to comment.

### 件の回答 (1)

David 2016 年 7 月 27 日
Hi Simrat,
Why not just forget about the symbolic toolbox. Declare your sub-equations and your final equation as normal anonymous functions instead of symbolic functions, which fzero can work with anyway. These have no problem appearing recursively:
y = @(x) sin(x)+cos(x)
z = @(x,y) -sin(y)+cos(x)
m = @(x) y(x)-z(x,y(x))
fzero(m,1)
Sometimes anonymous functions have trouble when you want to call them with array inputs. In this case you can wrap them using the function called arrayfun, or you could declare your subfunctions in their own m-files.
Dave

#### 0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

Translated by