You are on page 1of 4

INTRODUCTION TO MATLAB.

Write a function which returns a 2D matrix A and takes the size of matrix as argument where A(i,j) = 12+22+32+.+(i+j)2 Creating a function :
function z=return_matrix(ro,col) for i=1:ro for j=1:col temp=0; for k=1:(i+j) temp=temp+(k^2); end z(i,j)=temp; end end

Creating the main .m file :


t=1; while(t) ro = input('Enter the number of rows of your matrix: '); col = input('Enter the number of columns of your matrix: '); A=return_matrix(ro,col); disp(A); reply = input('Do you want to see more? Y/N [Y]: ', 's'); if reply=='n' t=0; end end

The trajectory of a moving object is defined as x(t)=5t; Y(t)=(1-x2(t)); z(t)=t2/2; t=0:0.1:5; Plot the trajectory in space. Plot (t,r) where r(t) is the distance from origin (0,0,0).

Diagram of t vs x :

Diagram of t vs y :

Diagram of t vs z :

Diagram of t vs r(t) :

XYZ plotting :

Explanation :
Imaginary parts of complex X, Y, and/or Z arguments ignored in trajectory at MATLAB

Appendix (code) :
t=0:.1:5; for i=1:length(t) x(i)=5*i; yy=1-(x(i)^2); y(i)=sqrt(yy); z(i)=(i^2)/2; rr=(x(i)^2)+(y(i)^2)+(z(i)^2); r(i)=sqrt(rr); end subplot(5,1,1),plot(t,x); subplot(5,1,2),plot(t,y); subplot(5,1,3),plot(t,z); subplot(5,1,4),plot(t,r); subplot(5,1,5),plot3(x,y,z);

You might also like