how to write a function in interval?
29 次查看(过去 30 天)
显示 更早的评论
hi,
can you please help me to write this function code in matlab?
thank you in advance
2 个评论
采纳的回答
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:
- create a vector of x values from -2 to 5.
- create a corresponding vector of y values by evaluating the function.
- plot y as a function of x.
- 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 个评论
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!