why plot result is different from fplot's
Ältere Kommentare anzeigen
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?
Akzeptierte Antwort
Weitere Antworten (1)
Jesus Sanchez
am 4 Mär. 2020
0 Stimmen
For plot, you wrote that x is defined between -pi and pi.
For fplot, you can see the reason in its reference page
6 Kommentare
pooneh shabdini
am 4 Mär. 2020
pooneh shabdini
am 4 Mär. 2020
Jesus Sanchez
am 5 Mär. 2020
Bearbeitet: Jesus Sanchez
am 5 Mär. 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
am 5 Mär. 2020
Jesus Sanchez
am 5 Mär. 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
am 5 Mär. 2020
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
