Finding full graph / minimum without an x range

9 ビュー (過去 30 日間)
Ashley Sullivan
Ashley Sullivan 2020 年 3 月 29 日
編集済み: dpb 2020 年 3 月 30 日
I am plotting a function and looking for its minimum, but the only parameter for the x value that I'm given is that it needs to be in increments of 1. I can also infer from the problem that the x must be positive.
Is there a function to make a "fit" of the graph without knowing an explicit x range? Right now, my method is to just guess for x variables until I get something that looks right, but I'd rather not do it that way.
  3 件のコメント
Ashley Sullivan
Ashley Sullivan 2020 年 3 月 29 日
To clarify: I need to find the minimum by both plotting and without plotting. Without plotting, I'm just using fminbnd.
Here is my function:
y = 0.04.*x.^2 + 0.3.*(16100./x).^2;
For x, the only information that I am given is that it should be plotted in increments of 1 and that it should be positive (given that it represents velocity). For graphing, I just guessed the interval:
x = 0:1:1000000;
I was wondering if there was an alternative I could put in to prevent me from having to guess.
Mohammad Sami
Mohammad Sami 2020 年 3 月 30 日
編集済み: Mohammad Sami 2020 年 3 月 30 日
y = @(x)0.04.*x.^2 + 0.3.*(16100./x).^2;
fplot(y);
fplot(y,[1 1000]); % to plot a range

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

回答 (1 件)

dpb
dpb 2020 年 3 月 30 日
編集済み: dpb 2020 年 3 月 30 日
Well, with such disparate magnitudes in terms, the interesting part is somewhat harder to envision...the second part goes to +inf @ origin while --> 0 as x-->inf so quadratic doesn't have any real counter effect until x gets large enough that the inverse x^2 term begins to go away...
To try to do something automagically to bound, I'd probably try something like
>> fnz=@(x) 0.04*x.^2 - 0.3*(16100./x).^2
fnz =
function_handle with value:
@(x)0.04*x.^2-0.3*(16100./x).^2
>> x0=fsolve(fnz,100)
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
x0 =
209.9802
>> xl=10.^fix(log10(z0)+[-1 1]);
>> yl=10.^fix(log10(z0)+[ 0 1]);
>> fplot(y,xl) % using Mohammed's function definition above here...
>> xlim(xl), ylim(yl)
>> hAx=gca;
>> hAx.XScale='log';
>> hAx.YScale='log';
>> grid on
produced

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by