Making a 3 Variable Function Into a 1 Variable Function

1 回表示 (過去 30 日間)
Rodolfo
Rodolfo 2013 年 11 月 5 日
コメント済み: Rodolfo 2013 年 11 月 7 日
Hello,
I have created the following simple function of the variable x,a, and b
f = 2*x - a - b.
What I want to do is set a and b equal to some constant values, for example a = b = 1. Now that I have set a and b equal to constants, my question is, how do I make this into a new function with just the variable x? For a = b = 1 , the new function should be 2*x - 2 . I want to do this so that I can use fzero to solve this new function numerically for x. Any help would be much appreciated.

採用された回答

Friedrich
Friedrich 2013 年 11 月 5 日
編集済み: Friedrich 2013 年 11 月 5 日
Hi,
have a look at the documentation. So basically
function f=my_fun(x,a,b)
f = 2*x - a - b;
Then you do:
f=@(x) my_fun(x,1,1)
And you call it with f(2) for example.
  1 件のコメント
Rodolfo
Rodolfo 2013 年 11 月 7 日
Thanks a lot Friedrich! This solved my problem! :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by