why plot result is different from fplot's
Mostra commenti meno recenti
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?
Risposta accettata
Più risposte (1)
Jesus Sanchez
il 4 Mar 2020
0 voti
For plot, you wrote that x is defined between -pi and pi.
For fplot, you can see the reason in its reference page
6 Commenti
pooneh shabdini
il 4 Mar 2020
pooneh shabdini
il 4 Mar 2020
Jesus Sanchez
il 5 Mar 2020
Modificato: Jesus Sanchez
il 5 Mar 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
il 5 Mar 2020
Jesus Sanchez
il 5 Mar 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
il 5 Mar 2020
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
