MATLAB Tutorial, Part 2: Plotting Parametric Curves
MATLAB Tutorial, Part 2: Plotting Parametric Curves
Khayms
Introduction to Engineering Fall 2003
Mathematics
c) Save file as
plot_demo1.m
d) Execute script:
>> plot_demo1
Plotting surfaces
>> [x,y]=meshgrid(-2:0.1:2,-2:0.1:2);
>> z=sin(x.^2+y.^2);
>> surface(x,y,z)
>> shading('interp');
>> grid on 3. Creating a function
>> colorbar
a) Open new .m file
b) Type in commands
function [ans]=dot_product(a,b)
ans=a(1)*b(1)+a(2)*b(2)+a(3)*b(3);
c) Save file as for i=1:n
dot_product.m product=product*i;
d) Execute function: end
c=
20
proj_a_onto_b =
3.7139
5. Programming in MATLAB
function [product]=factorial1(n)
product=1;