which x value is making maximum this function.

Hi there i need help about for loop. I have a code that gives me max value of a function. But i need to see which x value is making maximum this function.
clear all
clc;
maxy1=-inf;
for x=0:0.1:0.4
y1=-0.893*x^2;
maxy1 = max(maxy1,abs(y1));
end
maxy1
output should be like maxy1=3.9 when x=0.3.

回答 (1 件)

Ive J
Ive J 2021 年 1 月 31 日
編集済み: Ive J 2021 年 1 月 31 日

1 投票

x = 0:0.1:0.4;
y1 = -0.893.*x.^2;
[maxY1, maxIdx] = max(abs(y1));
x(maxIdx) % your answer is here

1 件のコメント

Mukaddes Bolat
Mukaddes Bolat 2021 年 1 月 31 日
it is giving me the max range value.

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

カテゴリ

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

質問済み:

2021 年 1 月 31 日

コメント済み:

2021 年 1 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by