MATLAB: Vector don’t equal when differentiating sin(pi*x)

differential equationsplotvector

I don't understand why i keep getting : Error using plot vector must be the same length.
As the data shows s1= 1X100and s2=1X99 which i don't understand why it has that data.
clc;
sym('x');
s= sin(pi*x);
x= linspace(0,4);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
s1= diff(s);
plot(x,s1)%Error at this line

Best Answer

see subs() (link) to better understand
x= linspace(0,4);
s= sin(pi*x);
subplot(2,1,1);
plot(x,s);
axis([0 4 -4 4]);
subplot(2,1,2);
syms x
s1= diff(sin(pi*x),x);
x= linspace(0,4);
plot(x,subs(s1,x))
Related Question