Homework 2 Solution

Homework 2 Solution - Lecture 2 MEEN 357 Homework Solution...

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

View Full Document Right Arrow Icon
Lecture 2 MEEN 357 Homework Solution 1 Lecture-02-Homework-Solution-2009.doc RMB 1. Problem 3.1 of the textbook. There is not a unique m-file. The following one has the essential elements. It also has comments inserted that might assist in understanding the approach. Solution: %Problem 3.1 on page 75 of the textbook %The problem is almost identical to the one on page 7 of the notes for %Lecture 3. %Approximations for cos(x) by Taylor Series %Given x=1.5 radians. clc clear all x=1.5 %Remember radians are dimensionless %The problem asks for eight terms. Therefore, n=7. n=7; %Put a title line on a table fprintf( '\n\t\tn\tapprox_cos\terror(Percent) \n' ); %Put a dividing line in table fprintf( '===============================\n' ); %Calculate the numbers for k=[1:1:n+1] if k==1 f(k)=1; approx_cos(k)=1; %Print the output for k-1=0 fprintf( '\t%5.0f %5.9f N/A\n' ,k-1,approx_cos(k)) else f(k)=(-1)^((k-1))*x^(2*(k-1))/factorial(2*(k-1)); approx_cos(k)=sum(f); error(k)=abs(((cos(x)-approx_cos(k-1))/cos(x)*100)); %Print the output for k-1=1,2,3,4,5 fprintf( '\t%5.0f %5.9f %5.4f\n' ,k-1,approx_cos(k),error(k)) end end This m-file yields the output n
Background image of page 1

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

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

Page1 / 4

Homework 2 Solution - Lecture 2 MEEN 357 Homework Solution...

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