Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Q1.

n = 8; m = 1;
r = randi(2000,m,n);
c = r-1000;
sum=0;
b=c;
disp(c);
for inx=1:n-1
for j=inx+1:n
if b(1,inx)>b(1,j)
temp = b(1,inx);
b(1,inx)=b(1,j);
b(1,j)=temp;
end
end
sum=sum+ b(1,inx);
end
median= b(1,n/2);
maxx = b(1,n);
sum = sum+maxx;
mean=sum/n;
min=b(1,1);
standard deviation
disp(b);
fprintf('\n max=%d min=%d midean=%d mean=%d', maxx, min ,median ,mean);

Q2.

Q3.

Q4.

Q5.

a)

b)

N=12;
syms x;
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y);
xi=[0.25 ,1 ,1.8, 2,2.3,3,3.4,4.2,5,5.6,6,6.2];
yi=sin(x);
n=N-1;
h=(x(N)-x(1))/1000;
a = zeros(n);
b = zeros(n);
c = zeros(n);
b(1)=(yi(2)-yi(1))/h;
a(1) = (yi(2)-yi(1))/h.^2 - b(1)/h;
c(1) = yi(1)-a(1)*xi(1).^2-b(1)*xi(1);
for i=1:n-1
b(i+1)=2*(yi(i+1)-yi(i))/h-b(i);
a(i+1) = (yi(i+2)-yi(i+1))/h.^2 - b(i+1)/h;
c(i+1) = yi(i+1)-a(i+1)*xi(i+1).^2-b(i+1)*xi(i+1);
%p=@(x,i)a(i)*(x-xi(i)).^2+b(i)*(x-xi(i))+c(i);
end
for i=1:n
hold on;
fplot(@(x) a(i)*(x-xi(i)).^2+b(i)*(x-xi(i))+c(i),[xi(i),xi(i+1)],'--');
end
hold off;
grid on;

You might also like