Question 1 --------------------------------------------------- function [lo,hi] = split(x) % Sort 1-d array X and reutrn 2 arrays: % LO contains all elements in X <= MEAN(X) % HI contains all elements in X > MEAN(X) % Sort array x = selectsort(x); % Define LO<=mean loloc = (x <= mean(x)); % locations lo = x(loloc); % values % Define HI~=LO hi = x(~loloc); %%%%%%%%%%%%%%%%%%%%%%%%%% function y = selectsort(y) % Sort and overwrite 1-d array Y in % ascending order len = length(y); for j = 1:len-1 % start of unsorted segment % Find min in unsorted segment [val,ind]=min(y(j:len)); ind = ind+j-1; % Swap min into correct position y([j ind]) = y([ind j]); end --------------------------------------------------- Question 2 --------------------------------------------------- function newtonRalston(x) % Find positive real root using Newton-Ralston % method given a starting point X. % Equation solved: % f(x)= x^4 - 8.6x^3 - 35.51x^2 + 464.4x - 998.46 % Parameters: % (use named constants--good programming style!) target = 0; % stopping value it = 0; % current no. of iterations maxit = 1000; % maximum no. of iterations eps = 0.001; % tolerance % Initial function value: f=x^4 - 8.6*x^3 - 35.51*x^2 + 464.4*x - 998.46; % Iterate for root: while ( abs(f-target)>eps & it=3 & cn>=3 for i=2:rn-1 for j=2:cn-1 grad_x(i-1,j-1)=(elevat(i,j+1)... -elevat(i,j-1))/(2*dx); grad_y(i-1,j-1)=(elevat(i+1,j)... -elevat(i-1,j))/(2*dy); end end end % save matrices in files save grad_x save grad_y ---------------------------------------------------