how to write a function in interval?

25 ビュー (過去 30 日間)
lina
lina 2014 年 10 月 21 日
回答済み: Rupa Kupireddy 2022 年 2 月 8 日
hi,
can you please help me to write this function code in matlab?
thank you in advance
  2 件のコメント
José-Luis
José-Luis 2014 年 10 月 21 日
編集済み: José-Luis 2014 年 10 月 21 日
What have you tried so far?
I would recommend you to read the "Getting started" part of the documentation.
You might want to look at the fzero() function.
doc fzero
doc plot
doc fplot
lina
lina 2014 年 10 月 21 日
I attached the question in jpg form can't write the code :'(

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

採用された回答

Matt Tearle
Matt Tearle 2014 年 10 月 21 日
MATLAB Academy can help you learn the basics of MATLAB. Also the Getting Started section of the doc, as Jose-Luis suggested.
For this specific question, you'll need to:
  1. create a vector of x values from -2 to 5.
  2. create a corresponding vector of y values by evaluating the function.
  3. plot y as a function of x.
  4. maybe pretty up the graph a bit.
For 2 you'll need to know about array operations. For 4 you can use xlabel, ylabel, title, xlim, ylim, and/or axis.
As Jose-Luis mentioned, if you need the roots exactly, you can use fzero, but that seems a bit advanced for HW#1. Because the function is a polynomial, you could also use polyval (for part 2) and roots. But, again, that seems more than is necessary.
  5 件のコメント
lina
lina 2014 年 10 月 21 日
pardon Matt but there is another problem in plotting dimension
x=(-2:5);
y=x.^4-5.*(x.^3)+2.*(x.^2)+6.*(x)-4;
plot(y,[-2,5]);
I get this error ??? Error using ==> plot Vectors must be the same lengths.
what should I do?
thank u in advance
Matt Tearle
Matt Tearle 2014 年 10 月 22 日
You don't need to specify the domain to the plot function, just the x values and their corresponding y values (in that order): plot(x,y)
If you want to adjust the axis limits that MATLAB chooses, use the xlim and/or ylim functions (use the doc to see how they work).

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

その他の回答 (1 件)

Rupa Kupireddy
Rupa Kupireddy 2022 年 2 月 8 日

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by