+
iAm.m | function x = iAm(yes,it,is,true) |
iAmNot.m | function x = iAm(no,it,is,false) |
usage with unmatching names | iAmNot(no,it,is,false) |
function plotSinx % usage: plotSinx % This function plots sin(x) from 0 to 2*pi % there are no inputs or outputs (other than the plot itself) % set the fixed domain x = linspace(0,2*pi); % define the sin function f = sin(x); % and plot plot(x,f) |
plotSinx.m |
function plotSin2 % usage: plotSin2 % This function plots sin(x) over a domain specified by user % We will query the user for input values then display a plot of sin(x) % over that domain % get starting and ending disp('You will define the plotting domain for sin(x).'); l = input('Enter the starting x value:'); h = input('Enter the ending x value:'); x = linspace(l,h); % define the sin function f = sin(x); % and plot plot(x,f) |
plotSin2.m |
function plotSin3(x) % usage: plotSin3(x) where x is a vector % This function plots sin(x) over a domain, x, specified by user % define the sin function f = sin(x); % and plot plot(x,f) |
plotSin3.m |
function plotSin4(a,b,n) % usage: plotSin4(a,b,n) % a = starting x value % b = ending x value % n = number of segments between a and b % define the domain from input values x = linspace(a,b,n); % define the sin function f = sin(x); % and plot plot(x,f) |
plotSin4.m |
function x = createRandInt % generate a pseudo-random number a = clock; x = round(a(6)); |
createRand.m |
function [r,theta] = cart2plr(x,y) % Convert Cartesian coordinates to polar coordinates % usage: [r,theta] = cart2plr(x,y) computes r and theta % from x and y values (arrays are allowed) % r = sqrt(x^2 + y^2); % theta = atan2(y,x); r = sqrt(x^2 + y^2); theta = atan2(y,x); |
cart2plr.m |
% This script will call a function to calculate the area and circumference % of a circle. User will supply the radius. clear all clc disp('We will find the area and circumference of any circle!'); r = input('What is the radius of your circle? '); % call our function that returns area and circumference [a,c] = circleData(r); fprintf('\nThe area of your circle is %.2f square units.\n\n',a); fprintf('The circumference of your circle is %.2f units.\n\n',c); |
scriptFn.m |
% This script will call a function to calculate the area
% and circumference % of a circle. User will supply the radius. clear all clc disp('We will find the area and circumference of any circle!'); r = input('What is the radius of your circle? '); % call our function that returns area and circumference [a,c] = circleData(r); fprintf('\nThe area of your circle is %.2f square units.\n\n',a); fprintf('The circumference of your circle is %.2f units.\n\n',c); function [a,c] = circleData(r) % return the area and circumference of a circle of any radius % usage: [a,c] = circleData(r) where r is the radius of the circle area = areaCalc(r); circum = circumCalc(r); % nested function to handle the area calculation function y = areaCalc(s) y = pi*s^2; end % nested function to handle the circumference calculation function z = circumCalc(t) z = 2*pi*t; end end |
scriptFn2.m |
function [a,c] = circleData(r) % return the area and circumference of a circle of any radius % usage: [area,circum] = circleData(r) where r is the radius of the circle area = areaCalc(r); circum = circumCalc(r); % nested function to handle the area calculation function y = areaCalc(s) y = pi*s^2; end % nested function to handle the circumference calculation function z = circumCalc(t) z = 2*pi*t; end end |
circleData.m |
function result=recursiveFn(x) % usage: recursiveFn(num) where num is a positive integer % This function computes the factorial of any positive integer if (x<=0) result=1; else result=x*recursiveFn(x-1); end end |
recursiveFn.m |
function x = createRandInt % generate a pseudo-random number a = clock x = round(a(6)); |
>> a |
"It has come to my attention, that air pollution is polluting the air!" |
"We can build a collective civic space large enough for all our separate identities, that we can be e pluribus unum -- out of one, many."
|