Minimum value from a vector for x in the range: x= [-4:0.5:4]; Calculate f(x)=x2+1.3x+2.

3 ビュー (過去 30 日間)
Ramesh
Ramesh 2024 年 2 月 2 日
コメント済み: Sam Chak 2024 年 2 月 2 日
How to solve this?
  3 件のコメント
VBBV
VBBV 2024 年 2 月 2 日
移動済み: Sam Chak 2024 年 2 月 2 日
use the function min and find the index at which this occurs in vector x
Sam Chak
Sam Chak 2024 年 2 月 2 日
Hi @Ramesh, does the visual help you to understand?
x = -2:0.5:2
x = 1×9
-2.0000 -1.5000 -1.0000 -0.5000 0 0.5000 1.0000 1.5000 2.0000
f = x.^2 + 1.3*x + 2
f = 1×9
3.4000 2.3000 1.7000 1.6000 2.0000 2.9000 4.3000 6.2000 8.6000
plot(x, f, '-o'), grid on, xlabel x, ylabel f(x)

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

回答 (1 件)

VBBV
VBBV 2024 年 2 月 2 日
編集済み: VBBV 2024 年 2 月 2 日
x = -4:0.5:4;
f = @(x) x.^2 + 1.3*x + 2
f = function_handle with value:
@(x)x.^2+1.3*x+2
[F idx] = min(f(x))
F = 1.6000
idx = 8
xv = x(idx) % value of x at which minimum of f(x) occurs
xv = -0.5000

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by