MATLAB: I have a figure window down below, I’m trying to plot both (x,y) and (x,yp) on the same graph, but only one line is showing up instead of two. I’m tried fixing it, but I can’t seem to figure it out. Any ideas? Thanks.

figuregraphplot

yp = @(x) sin(x)/x;
x = 1:0.2:10;
y = zeros(size(x));
nsize = 0.2;
a = 1;
b = a+nsize;
y(1)=5;
for i=2:length(y)
y(i)=((yp(a)+3*yp((2*a+b)/3)+3*yp((a+2*b)/3)+yp(b))/8).*(b-a)+y(i-1);
a = b;
b = b+nsize;
end
D1 = y;
figure
plot(x,y)
hold on
plot(x,yp(x))

Best Answer

yp = @(x) sin(x)./x; % ./