You are on page 1of 2

MATLAB Exercises week 3

For submission 19th Feb.

These questions are more open ended to train you how to approach a problem and decide for yourself what kind of code you need to write to find a solution. You will only need to write a small amount of code for each, but think about the structure of the script and the variables you will need before you start. Your answers should be in the form of a very brief mini report of one or two paragraphs, with plots and results as required. You will be marked not just for having the right answer, but for sensible code, clear commenting in the code, and how you use plots, labels, etc. to support your answer. Please include a copy of your script, but you need not show all intermediate output, like lists of vectors, etc.

Question 1: System of linear equations


x1 x 2 5 x3 4

(a) Consider the system of linear equations, 3x1 2 x 2 x3 8

. Write this system in

2 x1 x 2 1x3 3 matrix form, Ax=b. First show whether there is a valid solution for this system (HINT: A has to be nonsingular) then show that the system can be solved in the following ways:

I. Find the solution using MATLAB left division command \. II. Find the solution by using the inverse of the coefficient matrix x A 1b .

III. Find the solution via the transposed system x T b T A T in which A T A T this case we use the right division sign /

. In

Each of the equations can be rearranged in the form x3= Do this and then plot each of the planes in a 3D plot. Add the point which forms the solution to these equations and use your plot to explain what the solution means. You can change the viewing angle of a 3D plot with your mouse by clicking on the Rotate3D button in the plot window. (HINT: You will need to use the meshgrid and mesh commands to create these plots.)
x1 x 2 5 x3 4

(b) Now repeat the procedure in (a) for the following equations, 3x1 2 x 2 x3 8
2 x1 2 x 2 10 x3 5

Discuss your results using the 3D plots, as before.

Question 2. Polynomials (a) Write a script to solve the following polynomial: . Draw a plot of the polynomial in an appropriate range, and mark the roots on the plot. Indicate near the points on the plot whether the roots are simple roots, turning points or points of inflection. (b) Now change the coefficient of to accept a dynamic input from the user when the script is run. Run the script and try changing this value between 0.5 and 1.5. Discuss how the number of real roots changes. Draw a plot which shows the polynomial for a couple of different values, using labels and colours as needed.

Question 3: Plot an ellipse. (a) Write a script to draw an ellipse using x=acos, y=bsin. The script should accept inputs to dynamically change the size of the major (a) and minor (b) axes. Plot it with an appropriate scale (so that the relative lengths of a and b are clear) and add labels and titles as needed. Plot and label the major and minor axes. (b) Now use the rotation matrix below to rotate the ellipse by an angle in degrees defined dynamically by the user. Again, the major and minor axes and their labels should be shown in the rotated plot. As an answer you should show your script, and a graph for a=5, b=3. Show the original ellipse and one rotated by 45o on the same plot. HINT: For anticlockwise rotation in the x-y plane of an angle you can use the following relation to go from the co-ordinate pair (x,y) to the new co-ordinates (x_new,y_new): You wont be able to apply this matrix directly to the vectors for x and y. You will need to do some manipulation!

You might also like