Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. If you generate in MATLAB a row vector r containing all the foating point num

ID: 3800052 • Letter: 3

Question

3. If you generate in MATLAB a row vector r containing all the foating point numbers in a given system, another row vector y of the same dimension as containing 0s, and then plot discrete values of y vs using the symbol you'll get a picture of sorts of the floating point number system. The relevant commands for such a display are y zeros (1,length(x)); plot (x,y, Produce such a plot for the system (8,t,L, U) (2,3,-2,3). (Do not assume the IEEE special conventions.) What do you observe? Also, calculate the rounding unit for this modest floating point system. MacBook Pro

Explanation / Answer

Plot command:

>> x=0:.1:1; y =sin(2*pi*x);
>> plot(x,y);
Exercise:
>> x=[0,1]; y=sin(2*pi*x);
>> plot(x,y); % What is going on??
Options
Line type options: -,:,--,-.
>> plot(x,y,’-’);
>> plot(x,y,’:’);
>> plot(x,y,’--’);
>> plot(x,y,’-.’);
Color options: y,m,c,r,g,b,w,k
>> plot(x,y,’g’); % green line (line is default)
>> plot(x,y,’r’)
Marker options: .,o,x,+,*,s,d,v,^,<,>,p,h (type help plot)
>> plot(x,y,’x’); % blue star (blue is default)
Using several options together
>> plot(x,y,’*-r’); % red line with star markers
Plotting several curves
>> x=0:0.05:1; y1=sin(2*pi*x); y2=cos(2*pi*x);
>> plot(x,y1,x,y2)
>> plot(x,y1,’-b’,x,y2,’--r’)
>> x=0:0.05:2; y1=x; y2=x.^2; y3=x.^3; y4=x.^4;
>> plot(x,y1,’-b’,x,y2,’--r’,x,y3,’*g’,x,y4,’-c’)

Alternative, using hold command
>> x=0:0.05:1; y1=sin(2*pi*x); y2=cos(2*pi*x);
>> plot(x,y1,’-b’)
>> hold on
>> plot(x,y2,’--r’)
>> hold off
The axis command
>> axis([0,2,0,4])
>> axis equal
>> axis square % Use ’help axis’ to see what other options there are
Labelling
>> xlabel(’time t’)
>> ylabel(’position s(t)’)
>> ylabel(’position s(t)’,’FontSize’,16)
>> title(’Its important to label your graphs!’)
>> text(0.6, 2,’some text’,’FontSize’,16)
>> set(gca,’FontSize’,16)
>> legend(’x’,’x^2’)
Simplest Plots
>> plot(x) % Plots x vs its index, quick way to see what is in x
>> plot(x1,x2) % Careful! This does not plot x1 vs index
>> % and x2 vs index. Instead, plots x2 vx x1
>> plot(x1,x2,x3)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote