我喜欢使用Objective-C从一组复数中创建Argand Diagram。
是否有任何可用的解决方案或模板可以帮助我做到这一点?
有人可以推荐一种方法吗?
提供了类似的youtube链接,但它是一个Android程序:https://www.youtube.com/watch?v=s0oTeZ12_ig
- (void)ComputeABCD
{
double designFrequency = 1e9;
double simulateFrequency = 1.5e9;
double pi = 3.14159265359;
double omega = 2*pi*simulateFrequency;
double thetarad=1;
complex double cascadedA=1+0*I;
complex double cascadedB=0+0*I;
complex double cascadedC=0+0*I;
complex double cascadedD=1+0*I;
complex double A=0+0*I;
complex double B=0+0*I;
complex double C=0+0*I;
complex double D=0+0*I;
complex double newA=0+0*I;
complex double newB=0+0*I;
complex double newC=0+0*I;
complex double newD=0+0*I;
int index=0;
for (id element in storeImpedance)
{
id element2 = [storeLength objectAtIndex:index];
id element3 = [storeIndex objectAtIndex:index];
NSNumber *numberImpedance = (NSNumber *)element;
double valueImpedance = [numberImpedance doubleValue];
NSNumber *numberLength = (NSNumber *)element2;
double valueLength = [numberLength doubleValue];
NSNumber *numberIndex = (NSNumber *)element3;
NSInteger valueIndex = [numberIndex integerValue];
++index;
if (valueIndex==0)
{
thetarad=valueLength*pi/180*simulateFrequency/designFrequency;
A=cos(thetarad);
B=I*valueImpedance*sin(thetarad);
C=I*sin(thetarad)/valueImpedance;
D=cos(thetarad);
}
if (valueIndex==1)
{
thetarad=valueLength*pi/180*simulateFrequency/designFrequency;
A=1;
B=0;
C=(I*tan(thetarad))/valueImpedance;
D=1;
}
newA=cascadedA*A+cascadedB*C;
newB=cascadedA*B+cascadedB*D;
newC=cascadedC*A+cascadedD*C;
newD=cascadedC*B+cascadedD*D;
cascadedA=newA;
cascadedB=newB;
cascadedC=newC;
cascadedD=newD;
}
printf("The MAT ABCD is:\n");
printf("%g + %gi\n", creal(cascadedA), cimag(cascadedA));
printf("%g + %gi\n", creal(cascadedB), cimag(cascadedB));
printf("%g + %gi\n", creal(cascadedC), cimag(cascadedC));
printf("%g + %gi\n", creal(cascadedD), cimag(cascadedD));
}