I know a couple of you know C++ i'm trying to write a program that tells me resonance frequencies of a RLC circuit. I have everything almost done but i have to show the frequency at 10% below and above resonance and 20 intervals between them and also the impedance at same interval using the frequency at that interval, now comes the problem I was able to do the frequency fine but for some reason when i try to add the impedance the whole program comes wrong and only shows me 1 entry(solution or w/e you want to call it) instead of 20. Here's what i have so far maybe you can find what i did wrong. I think the problem is on the "for" part.
--------------------------------------------------------------------------------------
// examen(parte2).cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "math.h"
int _tmain(int argc, _TCHAR* argv[])
{float R,L,C,Fo,XL,XC,x,x1,x2,x3,x4;
printf("Entre el valor de la resistencia: ");
scanf("%f",&R);
printf("Entre el valor del inductor: ");
scanf("%f",&L);
printf("Entre el valor del condensador: ");
scanf("%f",&C);
Fo = 1/(2*3.14159265*sqrt(L*C));
printf("Frecuencia en resonancia es %f\n",Fo);
x1 = Fo*0.90;
printf("Frecuencia en resonancia a 10 porciento por debajo es %f\n",x1);
x2 = Fo+(Fo*0.10);
printf("Frecuencia en resonancia a 10 porciento por encima es %f\n",x2);
for(x=x1; x<=x2; x = x+(x2-x1)/20)
{
XL = 2*3.14159265*x*L;
XC = 1/(2*3.14159265*x*C);
x3 = (XL-XC)*(XL-XC) + R*R;
x4 = sqrt(x3);
printf("frecuencia= %f Impedancia= %f \n",x,x4) ;
}
getchar();
getchar();
return 0;
}
------------------------------------------------------------------------------------
program should look like this
http://i34.photobucket.com/albums/d1...resonancia.png
XI Wiki


