Skip to content

Instantly share code, notes, and snippets.

@KillerWhale12345
Last active February 11, 2017 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KillerWhale12345/24bd1157b039c5746742adcfeca088d5 to your computer and use it in GitHub Desktop.
Save KillerWhale12345/24bd1157b039c5746742adcfeca088d5 to your computer and use it in GitHub Desktop.
RC回路のステップ応答
/*
Vi(t) = RC*Vo(t)' + Vo(t)
*/
#include<stdio.h>
#include<stdlib.h>
#define R 1.0
#define C 1.0
#define INT_TIME 0.1
double dTime;
int main(void){
double dV,Us;
double dQ,dI,dVo;
int j;
printf("---Vi(t)=RCVo(t)'+Vo(t)---\n");
//初期値
dVo=0;//コンデンサーの電位差
dQ=0;//コンデンサーの電気量
dTime=0;//時刻
//ステップ入力
Us=1.0;
for(j=0;j<500;j++){
//抵抗の電位差
dV = Us - dVo;
//電流
dI = dV/R;
//電気量
dQ = dQ + dI*INT_TIME;
//コンデンサーの電位差
dVo = dQ/C;
//時刻
dTime = dTime + INT_TIME;
printf("TIME=%f\tVo=%f\n",dTime,dVo);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment