Why is my function giving me the wrong output ?
Mostrar comentarios más antiguos
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 comentarios
Star Strider
el 4 de Oct. de 2018
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
el 4 de Oct. de 2018
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
el 4 de Oct. de 2018
Respuestas (1)
madhan ravi
el 5 de Oct. de 2018
Editada: madhan ravi
el 5 de Oct. de 2018
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.
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!