assign1.sol - >> k=100 k = 100>> k=100>>...

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

View Full Document Right Arrow Icon
ASE 211 Solution to Homework 1 1. Using matlab, perform the following operations. Create a diary of your matlab session and hand in your diary. Also hand in all plots. >> r=2; r= 2 >> a=pi*r^2 a = 12.5664 >> sin(0) ans =
Background image of page 1

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

View Full Document Right Arrow Icon
0 >> sin(pi/2) ans = 1 >> cos(pi) ans = -1 >> x=[3;2;1;0] x = 3
Background image of page 2
2 1 0 >> y= [-15;3;2;1] y = -15 3 2 1 >> r*x ans = 6 4 2
Background image of page 3

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

View Full Document Right Arrow Icon
0 >> x+y ans = -12 5 3 1 >> A=[-4, 14, 0, 6; 20, 4, 2, 2;3, -2, 9, 1;5, 3, -7, 0] A = -4 14 0 6 20 4 2 2 3 -2 9 1 5 3 -7 0
Background image of page 4
>> r*A ans = -8 28 0 12 40 8 4 4 6 -4 18 2 10 6 -14 0 >> A*x ans = 16 70 14 14 >> z=[5,6,7,8]
Background image of page 5

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

View Full Document Right Arrow Icon
z = 5 6 7 8 >> A*z ??? Error using ==> * Inner matrix dimensions must agree. >> for i= 1:20 x(i)= pi*i/10 y(i)=sin(x(i)) end x = 0.3142 0.6283 0.9425
Background image of page 6
1.2566 1.5708 1.8850 2.1991 2.5133 2.8274 3.1416 3.4558 3.7699 4.0841 4.3982 4.7124 5.0265 5.3407 5.6549 5.9690 6.2832 y =
Background image of page 7

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

View Full Document Right Arrow Icon
0.3090 0.5878 0.8090 0.9511 1.0000 0.9511 0.8090 0.5878 0.3090 0.0000 -0.3090 -0.5878 -0.8090 -0.9511 -1.0000 -0.9511 -0.8090 -0.5878
Background image of page 8
-0.3090 -0.0000 >> plot(x,y)
Background image of page 9

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

View Full Document Right Arrow Icon
Background image of page 10
Background image of page 11

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

View Full Document Right Arrow Icon
Background image of page 12
Background image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: >> k=100 k = 100 >> k=100; >> while (k>=10) k=k-3; end >> k k = 7 >> alpha=[4;2;-3;3;2;6]; >> k=5; >> a=-2; >> b=2; >> plotpoly(alpha,k,a,b) >> diary off 2. Create the following m-Fle 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) 1 2 3 4 5 6-1-0.8-0.6-0.4-0.2 0.2 0.4 0.6 0.8 1 X Y=sin(X) Plot of Y vs. sinX-2-1.5-1-0.5 0.5 1 1.5-100-50 50 100 150 200 X Y Plot of Polynomial...
View Full Document

{[ snackBarMessage ]}

Page1 / 13

assign1.sol - >> k=100 k = 100>> k=100>>...

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

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