{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lab 11 work

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

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

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); }

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

View Full Document
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.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

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

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

View Full Document
Ask a homework question - tutors are online