why plot result is different from fplot's
Mostrar comentarios más antiguos
function [ Y ] = cosin( n,x)
s=size(x,2);
Y=zeros(1,s);
for i=1:n
Y=Y+((((-1)^(i-1))*(x.^((2*i)-2)))/factorial((2*i)-2));
end
end
I used this function once in plot and then in fplot:
x=-pi:pi/10:pi;
Y=cosin(600,x);
plot(x,Y)
result of plot was this shape:

syms x
fplot(cosin(600,x))
the result of fplot was this:

why plot just show this small part of cos(x) and not more?
Respuesta aceptada
Más respuestas (1)
Jesus Sanchez
el 4 de Mzo. de 2020
0 votos
For plot, you wrote that x is defined between -pi and pi.
For fplot, you can see the reason in its reference page
6 comentarios
pooneh shabdini
el 4 de Mzo. de 2020
pooneh shabdini
el 4 de Mzo. de 2020
Jesus Sanchez
el 5 de Mzo. de 2020
Editada: Jesus Sanchez
el 5 de Mzo. de 2020
hello Pooneh,
what do you mean that that is not the shape of a cosine function? As fas as I see it, its exacty the same. Periodic behaviour, having value y=1 at x=0 and -1 at x= pi = 3.14 etc etc
EDIT: I just realized that you are using cosin instead of cos. You could ocmpare your function with matlab function for cosine is cos(x). Just plot them at the same graph using hold on.
pooneh shabdini
el 5 de Mzo. de 2020
Jesus Sanchez
el 5 de Mzo. de 2020
I saw the result in matlab and it is indeed strange. The Taylor expansions resulting of Y gives "NaN" as a result for values of x that are not cointained within [-pi, pi].
The only mistake that I can see is that you have not written i-1 everywhere, so you are not implementeing correctly the function. I will give it more thought later!
pooneh shabdini
el 5 de Mzo. de 2020
Categorías
Más información sobre Surface and Mesh Plots 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!
