关于路灯优化用数学建模处理数据时候有个程序不知道怎么修改,大神帮我改一改好吗?在线等,感谢了!!!
#include<stdio.h>#include<math.h>doubles(doublel,doubleh);voidmain(){doublec,h,t[51],...
#include <stdio.h>
#include <math.h>
double s(double l, double h);
void main()
{
double c, h, t[51], delta, left, right, mid;
int i;
c = 20;
while (1)
{
scanf("%lf", &h);
if (h == 0)
break;
t[0] = 30;
for (i = 1; i <= 50; i++)
{
t[i] = s(i, h);
if ((t[i] - c) * (t[i-1] - c) <= 0)
break;
}
left = i-1;
right = i;
do
{
mid = left * 0.618 + right * 0.382;
if (s(mid, h) <= c)
left = mid;
else
right = mid;
delta = s(left, h) - c;
}
while (delta <= -1);
printf("l=%lf,%lf\n", left, delta);
}
}
double s(double l, double h)
{
double s,
p, d, k1, k2;
p = 250;
d = 7;
k1 = h * h + d * d + l * l * 2.25;
k1 = sqrt(k1 * k1 * k1);
k2 = h * h + d * d + l * l * 0.25;
k2 = sqrt(k2 * k2 * k2);
s = 2 * p * h * (1 / k1 + 1 / k2);
return s;
}
最后的double s的函数我把P=2200改成P=250之后就运行不了了,求解为什么会这样?这个程序是我在网上找的,原来是功率是2200w的路灯,路灯高度是h,路宽d=7m,最低照明强度是C0=20W/m^2,程序是计算最优的路灯间距的,我想换成我们学校的实际情况,路灯是250w的,路灯高8米,路宽7米,请问该怎么改呢?大神们解答一下,急用呀!!帮帮忙!!感激不尽 展开
#include <math.h>
double s(double l, double h);
void main()
{
double c, h, t[51], delta, left, right, mid;
int i;
c = 20;
while (1)
{
scanf("%lf", &h);
if (h == 0)
break;
t[0] = 30;
for (i = 1; i <= 50; i++)
{
t[i] = s(i, h);
if ((t[i] - c) * (t[i-1] - c) <= 0)
break;
}
left = i-1;
right = i;
do
{
mid = left * 0.618 + right * 0.382;
if (s(mid, h) <= c)
left = mid;
else
right = mid;
delta = s(left, h) - c;
}
while (delta <= -1);
printf("l=%lf,%lf\n", left, delta);
}
}
double s(double l, double h)
{
double s,
p, d, k1, k2;
p = 250;
d = 7;
k1 = h * h + d * d + l * l * 2.25;
k1 = sqrt(k1 * k1 * k1);
k2 = h * h + d * d + l * l * 0.25;
k2 = sqrt(k2 * k2 * k2);
s = 2 * p * h * (1 / k1 + 1 / k2);
return s;
}
最后的double s的函数我把P=2200改成P=250之后就运行不了了,求解为什么会这样?这个程序是我在网上找的,原来是功率是2200w的路灯,路灯高度是h,路宽d=7m,最低照明强度是C0=20W/m^2,程序是计算最优的路灯间距的,我想换成我们学校的实际情况,路灯是250w的,路灯高8米,路宽7米,请问该怎么改呢?大神们解答一下,急用呀!!帮帮忙!!感激不尽 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询