All codes must be entered in matlab Unless specifically stat
All codes must be entered in matlab
Unless specifically stated in a question only allowed Matlab functions can be used.
Allowed functions are; fprintf, input, plot, mesh, surf, contour
Functions allowed in one question are not allowed to answer other questions.
10. Write a program to compute the series k- Continue to compute this series until it converges to within 0.000000001 (i.e. 10-9) Print the value of this series and the number of terms in the series in the command window Compute the ratio of to the value of the above series, print the result to the screen with 6 decimal places and comment on the result. (25 points) 11. Write a program to generate an array of the series m, m-1, ...2,1 m, m Where the short repeating pattern contains m values and this repeats n times Generate and plot this array for m-10 and n 10. (15 bonus points)Solution
/* Merges array N[] of size n into array mPlusN[]
of size m+n*/
int merge(int mPlusN[], int n[], int m int n)
{
int i=n; /* current index of i/p part of mplusN[]*/
int j=0; /* current index of N[]*/
int k=0; /* current index of output mlusN[]*/
while (k<(m+n))
{
/* Take an element from mPlusN[] if
a) value of the picked element is smaller and we have not reached end of it
b) we have reached end of N[] */
if ((i<(m+n) && mplusN[i] <= N[j]) || (j==n))
{
mPlusN[k] = mPlusN[i];
k++;
i++;
}
else // Otherwise take element from N[]
{
mPlusN[k] = N[j];
k++;
j++;
}
}
}

