compexam2 - comp4 function [avg, med] = newstats(u)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Question1 function output=function_name(t) Output=t+1 end functionName = @(varname)funcexpres h = @(x) g(f(x)); h(2) Loop quest2 for x=1:1:10 Disp(x) end x=1 while(x<10) disp(x) x=x+1 end comp2 x=linspace(0,30,100) y=sin(x) plot(x,y) x=linspace(0,30,100) y=sin(x) z=cos(x) plot3(x,y,z) interpolation x = 1:5; y = [2 6 6.2 7.4 10]; newx = 1:0.1:5; newy = interp1(x,y,newx); plot(x,y,’O’,newx,newy) curved x = 1:5; y = [2 6 6.2 7.4 10]; newx = 1:0.1:5; newy = spline(x,y,newx); plot(x,y,’O’,newx,newy) polynomial x = [ 1 2 3 4 5]; y = [ 9 22 41 66 97]; coeffs = polyfit(x,y,2)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: comp4 function [avg, med] = newstats(u) %primfunct % NEWSTATS Find mean and median n = length(u); avg = mean(u, n); med = median(u, n); function a = mean(v, n) % Subfunction % Calculate average. a = sum(v)/n; function m = median(v, n % Subfunction % Calculate median. w = sort(v); if rem(n, 2) == 1 m = w((n+1) / 2); else m = (w(n/2) + w(n/2+1)) / 2; end animation t = 0:0.1:20; x=t.*cos(5*t); y=5*sin(t); for k = 1:length(x) pause(0.05) plot(x(k),y(k),'X') axis([min(x) max(x) min(y) max(y)]) end...
View Full Document

Ask a homework question - tutors are online