5.6 How to make table of \(x,y\) values and plot them

Generate a list or table of \((x,\sin (x))\) values and plot them.

Mathematica

lst=Table[{x, Sin[x]}, {x, -Pi, Pi, 1/10}]; 
ListLinePlot[lst]
 

pict

 

Matlab

Matlab does not have a nice function like Table so one can either make the \(x\) variable and then use it to make \(\sin (x)\)

or use arrayfun

close all; 
x=-pi:.1:pi; 
plot(x,sin(x));
 

Using arrayfun

A=cell2mat(arrayfun(@(x) [x;sin(x)],... 
       -pi:.1:pi, 'UniformOutput',false)); 
plot(A(1,:),A(2,:))
 

pict