Purchase Solution

MATLAB Code Functions

Not what you're looking for?

Ask Custom Question

1. Construct your own MATLAB function realizing the insertion sort algorithm.
Your function should have an unsorted array as its input and the sorted array as the output. In particular, you will need:
(i) Draw a flowchart of the function realizing the insertion sort
(ii) Write the corresponding MATLAB code. You should check (just for yourself) how your function works with an arbitrary unsorted array.

2. Write your own function computing cos(x) based on the Taylor expansion of cos(x) in the vicinity of zero. Name this function my_cos(x, N, eps). The input parameters in this function should be: x- the argument; N - the initial number of terms in the expansion; eps -optional parameter, giving the accuracy of approximation. In particular, you will need to do:
(i) Write MATLAB code for a function computing cos(x) based on the Taylor expansion with the fixed number of terms N in the expansion. Name
this function my_cos1(x,N). Draw a flowchart of my_cos1
(ii) (8 marks) Write a MATLAB code for my_cos(x,N,eps) based on the function my_cos1(x,N). 'Eps' is an optional parameter, the giving the accuracy. In other words, your function can used in two modes: my_cos(x,N,eps) and my_cos(x,N). Draw a flowchart of my_cos.

Hint: if we need to compute cos(x) with a given accuracy ?, we can truncate the infinite part of Taylor expansion cos(x)=a0+a1 x+a2 x2+... + an xn+...starting with the term an xn in case we have |an xn|<?.

3. You are computing now the roots of a nonlinear equation f(x)=0 with the accuracy ? based on the bisection method (use Wikipedia for details about the method, section 'The method'). The given accuracy is achieved in case |f(c)|< ? , where c- is an approximate root of the equation.
You will need to construct your own MATLAB function bisect_1(fname, a, b, eps), where fname - is the name of the function; a,b, determine the initial interval for the root search; eps is the accuracy.
(i) Draw a flowchart of bisect_1(fname, a, b, eps).
(ii) Write MATLAB code for bisect_1(fname, a, b, eps).
(iii) Find all roots of the equation exp(- cos(x)) -1=0 in the interval 0<x<3

Purchase this Solution

Solution Summary

MATLAB code functions are determined. The function computes cos(x) based on the Taylor expansion of cos(x) in the vicinity of zero.

Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.