Recommended problems

1. problem: Write a function called saddleM, which takes a matrix as an input. The output is a list of positons of the items, which are greater that the sum of their indicies.

function outp=saddleM(inmatrix)
outp=[];
for i=1:size(inmatrix,1)
    for j=1:size(inmatrix,2)
        if inmatrix(i,j)>i+j
            outp=[outp; i j];
        end
    end
end

2. problem: Write a function called firstL, which takes a vector as an input. The output is the position of the first item of the vector which is grater than 6. If there is no such item, than the output is -1.

3. problem: Write a function called flatV, which takes a vector as an input, say v. The output is a vector, its element are zeros between the first and the ith position, where i is the first position where v(i) is greater then 100. After the ith position the elements of the output are the same as v's.

function ki=nullaz(v)
ki=v;
k=1;
while k<=length(v)
   if v(k)>100
       break
   end
   ki(k)=0;
   k=k+1;
end

4.problem: Write a function called reciP, which takes an integer as an input, say n. The output is the smallest integer k for wich the sum 1 + 1/2 + 1/3 + · · · + 1/k is greater then n. If more than 10^5 term would be necessary, then the output shall be -1 instead of k.

5. problem: Write a function called secondS, which takes 3 number as an input, a, b and c. They are the coefficionts of the equation ax^2+bx+c=0. The outputs are the two roots of this equation, calculated with the modified solving formula that prevents simplification in case b>>a,c.

function [root1, root2]=secondS(a,b,c)
% Let us suppose, that a~=0
if a==0
    error('The coefficient of the second order term is zero')
end

D=sqrt(b^2-4*a*c);

if b>0
    root1=-2*c/(b+D);
    root2=(-b-D)/(2*a);
elseif b<0
    root1=(-b+D)/(2*a);
    root2=(-2*c)/(b-D);
else
    root1=(+D)/(2*a);  
    root2=(-D)/(2*a);    
end

6. problem: Write a function called estiLn, which takes a positve number as input, say n. The output is the estime of log(1.5) using the first n terms of the Taylor series, that is $ln(1+0.5)=\sum_{k=1}^{\infty} -(-0.5)^k/k$.

function outp=saddleM(inmatrix)
outp=[];
for i=1:size(inmatrix,1)
    for j=1:size(inmatrix,2)
        if inmatrix(i,j)>i+j
            outp=[outp; i j];
        end
    end
end