ASE 211 - Homework 1 Due Jan. 23

ASE 211 - Homework 1 Due Jan. 23 - plotpoly.m : function

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
ASE 211 Homework 1 Due: In class, Wednesday, January 23rd. 1. Using matlab, perform the following operations. Create a diary of your matlab session and hand in your diary (use diary command in matlab). Also hand in all plots. Enter r = 2. Compute a = πr 2 . Compute sin (0), sin ( π/ 2) and cosπ . Enter column vectors x = (3 , 2 , 1 , 0) and y = ( - 15 , 3 , 2 , 1). Compute r * x and x + y . Create a matrix A = - 4 14 0 6 20 4 2 2 3 - 2 9 1 5 3 - 7 0 Multiply r * A and A * x . Enter a row vector z = (5 , 6 , 7 , 8). Now try to multiply A * z . You should get an error message. Perform the following for-loop: for i = 1 to 20 by 1, x ( i ) = π * i/ 10 and y ( i ) = sin ( x ( i )). Plot the vector x vs. y. Print the plot. Enter k=100. Perform the following while-loop: while k is greater than or equal to 10, decrement k by 3. 2. Create the following m-file
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: plotpoly.m : function plotpoly(alpha,k,a,b) % % function which plots the polynomial % alpha(1)*x^k+alpha(2)*x^{k-1}+. ...+alpha(k)*x+alpha(k+1) % for x between a and b. k is the degree of the polyomial, and alpha % is a vector of coefficients % h=(b-a)/100; for i=1:101 x(i)=a+(i-1)*h; sum=0; for j=1:k+1 sum=sum+alpha(j)*x(i)^(k+1-j); end y(i)=sum; end plot(x,y) In matlab, type the following commands: >> alpha=[4;2;-3;3;2;6]; >> k=5; >> a=-2; >> b=2; >> plotpoly(alpha,k,a,b) Print the plot created by these commands. You have just plotted the polynomial 6 + 2 x + 3 x 2-3 x 3 + 2 x 4 + 4 x 5 on the interval between -2 and 2....
View Full Document

Page1 / 2

ASE 211 - Homework 1 Due Jan. 23 - plotpoly.m : function

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online