Hi.. here's my code
x=[0.1, 0.5, 1]
x_e=[0.1, 0.5, 1]
g=x.^2+2*x_e
g(2)
x(find(g(2)))
I want to find which x value corresponds to g function's 2nd value, but it gives me wrong answer: x=0.1, but the right one is x=0.5. How can I fix it?

1 件のコメント

Paresh yeole
Paresh yeole 2020 年 6 月 10 日
編集済み: Paresh yeole 2020 年 6 月 10 日
find(g(2))
will return 1 as g(2) is greater than zero.
if you have to find corresponding x value then use
find(x == g(2))
But in your case it will return empty vector as there is no value in x which is equal to 2nd value in g.
Read more about find :

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

 採用された回答

madhan ravi
madhan ravi 2020 年 6 月 10 日
編集済み: madhan ravi 2020 年 6 月 10 日

0 投票

X = interp1(g,x,g(2))
%or
X = x(abs( g - g(2) ) < 1e-2)

1 件のコメント

Ani Asoyan
Ani Asoyan 2020 年 6 月 10 日
thank you !

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2020 年 6 月 10 日

編集済み:

2020 年 6 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by