我是 iOS 编程/目标 c 的新手,我正在尝试进行迭代试验和错误计算,但我被卡住了。通常这段代码可以在 excel VBA 中工作,所以我不确定如何在 obj C 中克服这个问题:
- (IBAction)calculate:(id)sender {
static float friction=2;
static float difference;
float Re = [pipe_id.text floatValue] * [fluid_velocity.text floatValue] / [kin_viscosity.text floatValue];
ReynoldsNo.text = [[NSString alloc]initWithFormat:@"%6.2f", Re];
do{
float Colebrook1 = 1/powf(friction,0.5);
float Colebrook2 = -2*log10f([RelativeRoughness.text floatValue]/(3.7*[pipe_id.text floatValue]) + 2.51/(Re*powf(friction,0.5)));
float difference = fabsf((Colebrook1-Colebrook2)*1000);
friction = friction - 0.000001;
FrictionFactor.text = [[NSString alloc]initWithFormat:@"%6.2f", friction];
Cole1.text = [[NSString alloc]initWithFormat:@"%6.2f", Colebrook1];
Cole2.text = [[NSString alloc]initWithFormat:@"%6.2f", Colebrook2];
}while (difference > 0.000001);
}
所以当我编译这个时,摩擦值保持在 2。我的循环不起作用,所以整个试验和错误的事情已经分崩离析。我需要一些帮助来了解如何用目标 C 编写它。感谢您的帮助,ALM。