Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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