Why is my function giving me the wrong output ?
이전 댓글 표시
Matlab for me is a new program. I have to write and plot the function : fb (x) = xe^(-x+1) - sin(2x )+ x - 7/2, but my x goes from inf to inf. I have written it like this :
function [ y ] = fb ( x )
y = x.*exp(-x+1)-sin(2*x)+x-(7/2)
end
and I tried with this script :
x=-5:5;
y=fb(x)
plot(x,y,'r')
What is wrong with my way of thinking ? thank you
댓글 수: 3
Star Strider
2018년 10월 4일
Your script and function work correctly when I run them.
I do not understand ‘... my x goes from inf to inf.’
Please explain this. What do you want to do?
Cam Salzberger
2018년 10월 4일
I don't see an issue. When I run your code, I get this:

Did you have a figure open already, with axes in an unusual location? Try opening a new figure before plotting?
AMELA SHAHINI
2018년 10월 4일
답변 (1개)
madhan ravi
2018년 10월 5일
편집: madhan ravi
2018년 10월 5일
syms x
y = x.*exp(-x+1)-sin(2*x)+x-(7/2)
fplot(y)
grid on
x=vpasolve(y==0,x)
Note: Make sure you have symbolic toolbox.
Remark: fplot (symbolic) command executes from -inf to inf.
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!