This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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
 Spring '08
 Unknown
 #define, London Buses route K3, Daewoo K3, London Buses route K4, Transdev London

Click to edit the document details