I have plotted a parabola like curve in the rough shape of (y=x^2). How am I able to draw plot a verical line from the minimum of the graph where the gradient is zero to the x axis and have this labbled as (Xminimum). Is it also possible to obtain an x value at which this value occurs on the graph too
Thanks

 採用された回答

Mark Sherstan
Mark Sherstan 2018 年 12 月 13 日
編集済み: Mark Sherstan 2018 年 12 月 13 日

3 投票

Use the islocalmin function:
x = -5:0.1:5;
y = x.^2;
idx = islocalmin(y);
figure(1)
hold on
plot(x,y)
plot(x(idx),y(idx),'*r')
legend('Curve','Local Min')
hold off
fprintf('Min located at %0.2f\n',x(idx))

5 件のコメント

Andrew Kay
Andrew Kay 2018 年 12 月 13 日
Is it possible to have a vetical line drawn from from the minimum to the x axis? Basically my graph isnt exactly a 'y=x^2' graph and doesnt touch the x axis. I only said that for sy in understaning. Thanksimplicit
Mark Sherstan
Mark Sherstan 2018 年 12 月 13 日
Use the line function! Here you go :)
x = -5:0.1:5;
y = x.^2 - 5;
idx = islocalmin(y);
figure(1)
hold on
plot(x,y)
plot(x(idx),y(idx),'*r')
line([x(idx) x(idx)],[y(idx) 0])
hold off
fprintf('Min located at %0.2f\n',x(idx))
Andrew Kay
Andrew Kay 2018 年 12 月 13 日
Great that works excellent thanks! Is there a way i can chose the colour of that line/ a coloured dashed line?
Mark Sherstan
Mark Sherstan 2018 年 12 月 13 日
Right now this is a black dashed line. More options can be found towards the bottom of the page here.
line([x(idx) x(idx)],[y(idx) 0],'color','k','LineStyle','--')
Andrew Kay
Andrew Kay 2018 年 12 月 13 日
Very Helpful, thanks for your time

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 12 月 13 日

0 投票

syms x
y=x^2
x=solve(diff(y)==0)

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

質問済み:

2018 年 12 月 13 日

コメント済み:

2018 年 12 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by