how to change variable value from another function

7 ビュー (過去 30 日間)
yon am
yon am 2018 年 6 月 22 日
コメント済み: yon am 2018 年 6 月 22 日
Hi, is there any way to change the value of a and b without change the function's signature. like global variable in c?
  1 件のコメント
Stephen23
Stephen23 2018 年 6 月 22 日
編集済み: Stephen23 2018 年 6 月 22 日
"is there any way to change the value of a and b without change the function's signature"
There may well be, but it would be buggy, quite horrible code. Ugh, global variables....
I think the more important question is why do you want to do this? What is your actual reason for specifying "...without change the function's signature"? Why can't you change the function, or use function parameterization? It seems to me that this question shows a very high probability of this problem:
What is the real issue that you are having?

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

採用された回答

Steven Lord
Steven Lord 2018 年 6 月 22 日
If by "implementation of brent" you mean Brent's method, depending on how that's implemented you may be able to write your function that accepts a, b, and c as inputs and use one of the parameterizing techniques from this documentation page to fix a and b and let the Brent's method implementation call the parameterized function with values for c as Stephen suggested.
  1 件のコメント
yon am
yon am 2018 年 6 月 22 日
i will use it to change a and b.

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

その他の回答 (1 件)

yon am
yon am 2018 年 6 月 22 日
編集済み: yon am 2018 年 6 月 22 日
i found this
function [n] =try_b(t)
global a
global b
a=a*t;
b=b*(1-t);
i can't change the signature because i am using implementation of brent and i should pass this function as a variable to brent function which gets a function with one argument.
  2 件のコメント
Stephen23
Stephen23 2018 年 6 月 22 日
@yon am: don't use global variables. Parameterizing the function is more efficient, and less buggy.
yon am
yon am 2018 年 6 月 22 日
thanks a lot

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by