lab 11 work - ME 218 (17795) Alan Shu-Ming Kwok (sk25784)...

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

View Full Document Right Arrow Icon
ME 218 (17795) Alan Shu-Ming Kwok (sk25784) Lab 11 a. Write a program that prompts a user for the initial condition e(0), h, and t end and uses Euler’s Method to determine the value e(t) at each time step. Output the values to a text file in the format below. #include <iostream> using namespace std; #define R 0.1 #define C 1.0 void main() { //initalize float h, tend; float e[1000]; float dedt[1000]; //user intput cout << "e(0) = " ; cin >> e[0]; cout << "h = " ; cin >> h; cout << "t-end = " ; cin >> tend; //output text FILE *lab11; lab11 = fopen( "//disk.austin.utexas.edu/root/engrstu/ME/sk25784/Desktop/ testing.txt" , "w" ); fprintf(lab11, "t \t\t e(t) " ); //Euler Method Print for ( int i = 0; i <= tend/h; i++) { dedt[i] = -e[i] / (R*C); e[i+1] = e[i] + h*dedt[i]; fprintf( lab11, "\n%f \t %f" , i*h, e[i]); } fclose(lab11); }
Background image of page 1

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

View Full DocumentRight Arrow Icon
ME 218 (17795) Alan Shu-Ming Kwok (sk25784) Lab 11 b) Import the text file into Excel and plot the voltage e(t) vs. time. Be sure and label your graph.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/04/2011 for the course ME 218 taught by Professor Unknown during the Spring '08 term at University of Texas at Austin.

Page1 / 6

lab 11 work - ME 218 (17795) Alan Shu-Ming Kwok (sk25784)...

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

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