labro11 - Code: #include <stdio.h> #include...

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

View Full Document Right Arrow Icon
Doug Rivas ME 218 Lab 11 M 5-7 11.1 Code: #include <stdio.h> #include <math.h> #define R .1000 #define C 1.0000 int main(void) { double h; double y; double dy; double t; t=0; y=4; h=.05; printf("time, t voltage, y\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
while(t<1.05) { dy= -y/(R*C); printf("%lf %lf\n", t, y); y=y+ h*dy; t= t+.05; } } 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 0 0.2 0.4 0.6 0.8 1 1.2 Voltage vs. Time Voltage vs. Time Time 11.2 Code: #include <stdio.h> #include <math.h> #define R .1000 #define C 1.0000 int main(void) { double h; Voltage
Background image of page 2
double y; double dy; double t; double k1; double k2; double k3; double k4; double slope; t=0; y=4; h=.05; printf("time, t voltage, y\n"); while(t<1.05) { k1= -y/(R*C); k2= y+(h/2)*k1; k3= y+(h/2)*k2; k4= y + h*k3; slope= (k1+2*k2 + 2*k3 +k4)/6; printf("%lf %lf\n", t, y); y=y+ h*slope; t= t+.05; } }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Voltage vs Time 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 0 0.2 0.4 0.6 0.8 1 1.2 Series1 Time 11.3
Background image of page 4
Background image of page 5

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

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

Unformatted text preview: Code: #include <stdio.h> #include <math.h> #define R .1000 #define C 1.0000 #define Pi 3.14159265 double t; double volt(double t); int main(void) { double h; double y; double dy; double t; double k1; double k2; double k3; double k4; double slope; Voltage t=0; y=4; h=.05; printf("time, t voltage, y\n"); while(t<1.05) { k1= -y/(R*C) + volt(t); k2= y+(h/2)*k1; k3= y+(h/2)*k2; k4= y + h*k3; slope= (k1+2*k2 + 2*k3 +k4)/6; printf("%lf %lf\n", t, y); y=y+ h*slope; t= t+.05; } } double volt(double t) { double v; v=10*exp(-t*20)*sin(t*2*Pi/.03); return v; } Output: Excel Plot: Voltage vs Time (with variable voltage across capacitor) 0.5 1 1.5 2 2.5 3 3.5 4 4.5 0.2 0.4 0.6 0.8 1 1.2 Series1 Time Voltage...
View Full Document

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

Page1 / 6

labro11 - Code: #include <stdio.h> #include...

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

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