calling a funcion in a loop and replacing input variable with output variable

So I have the funcion:
function y=function_for_Ex6a(x)
% This is a simple function
y=4*(1-cos(x)).^2+x.^3;
end
And I want to use a for loop to run through this function 100 times with an initial input of x=4. I need the output value of y to replace the input value for each interation. Any ideas? Please don't just send links to other websites. Thanks.

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 3 月 1 日
編集済み: KALYAN ACHARJYA 2019 年 3 月 1 日
%My Answer is based on what I have understood, if any issue please clarify it.
function y=function_for_Ex6a(x)
y=4*(1-cos(x)).^2+x.^3;
end
Now call the function
y=function_for_Ex6a(4);
for i=1:100
y=function_for_Ex6a(y) % You can use indexing y(i), if required
end
More
y(1)=function_for_Ex6a(4);
for i=2:100
y(i)=function_for_Ex6a(y(i-1));
end

2 件のコメント

Gregory Power
Gregory Power 2019 年 3 月 1 日
Thank you.
Harshini
Harshini 2025 年 1 月 15 日
tottally fine

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2018b

質問済み:

2019 年 3 月 1 日

編集済み:

2025 年 1 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by