小弟实在不会做,求高手帮忙,谢谢了,是这样的,这道题:
已给出一个method: public static long evaluations; public static double func(double x)
{
double result; result = Math.abs( Math.sin(0.017453292519943295769236907684886*x) * (x/90) ); evaluations++;
return result;
}
}还给这个method一些例子
public static void main(String args[])
{
/* The following are examples of how you should keep track of the evaluations */
evaluations=0; // Reset evaluations to 0 before starting task
System.out.println(func(1.23));
System.out.println(func(4.56));
System.out.println(func(7.89));
System.out.println("Performed in "+evaluations+" function evaluations."); // Print evaluations after finishing task evaluations=0; // Reset evaluations to 0 before starting task
System.out.println(func(1.23));
System.out.println(func(4.56));
System.out.println(func(7.89));
System.out.println(func(0.12));
System.out.println(func(3.45));
System.out.println(func(6.78));
System.out.println("Performed in "+evaluations+" function evaluations."); // Print evaluations after finishing task
}
}
如何通过调用这个method,通过输入x的范围如(0-180)
高()宽()来画出如下的抛物线图程序还要画出抛物线的同时,显示出y 的最大值 和最小值,和 计算次数我快交作业了,求高手帮忙吧,谢谢啦
已给出一个method: public static long evaluations; public static double func(double x)
{
double result; result = Math.abs( Math.sin(0.017453292519943295769236907684886*x) * (x/90) ); evaluations++;
return result;
}
}还给这个method一些例子
public static void main(String args[])
{
/* The following are examples of how you should keep track of the evaluations */
evaluations=0; // Reset evaluations to 0 before starting task
System.out.println(func(1.23));
System.out.println(func(4.56));
System.out.println(func(7.89));
System.out.println("Performed in "+evaluations+" function evaluations."); // Print evaluations after finishing task evaluations=0; // Reset evaluations to 0 before starting task
System.out.println(func(1.23));
System.out.println(func(4.56));
System.out.println(func(7.89));
System.out.println(func(0.12));
System.out.println(func(3.45));
System.out.println(func(6.78));
System.out.println("Performed in "+evaluations+" function evaluations."); // Print evaluations after finishing task
}
}
如何通过调用这个method,通过输入x的范围如(0-180)
高()宽()来画出如下的抛物线图程序还要画出抛物线的同时,显示出y 的最大值 和最小值,和 计算次数我快交作业了,求高手帮忙吧,谢谢啦
解决方案 »
- WEBWORK 标签问题
- JMF录制视频报了一个An unexpected error,很诡异,敬请高手关注
- 如何建立一个自定义类型的向量Vector?
- WebLogic8.1插入MySql数据库中文乱码问题!
- SWT中setenabled(false)在哪里把字体颜色设成灰色的
- 新手求教:关于输入数字,用起泡法排序的问题
- 基础问题,同一程序在不同语言实现下的不同结果!
- 急需帮助:请问java.net.SocketException: Too many open files,一般是什么情况引起的,应该什么解决!!!!
- XML的读取的问题,递归还是面向对象?
- 如何检验Java虚拟机是否存在??? 谢谢 在线求答!!!
- Swt做的浏览器超链接问题
- 新手 java运行
这是干吗用的,看不懂
这里0.017453292519943295769236907684886 = Pi/180
也就是sin(0.017453292519943295769236907684886*x)在180内为一个周期,所以要分类讨论:
1。如果宽度小于一个周期(180),则很简单,直接将横坐标,纵坐标按照比例进行缩放或者扩大
2。如果宽度大于一个周期,情况就有点复杂了显然这里应该是第一情况:
这里关键是要在180内找出,哪一点对应一个最大的y值。
求导: 得出tan(0.017453292519943295769236907684886*x) = -0.017453292519943295769236907684886*x如果会解方程的,可以直接得到解。否则就用遍历的方法,得出对应的x的大致范围。 可以从方程式中看出,就是y=tan(x)和y=-x两者相交的点所以,0.017453292519943295769236907684886*x应该在(PI , 2/3*PI)之间
遍历得到大概x=116的时候,此值是最大的 1.1584456596744819 跟标准答案差不多了,这里精度的关键就是要解上面那个方程了。
第二步,输出曲线。 这里的关键就是横纵坐标的缩放和扩大了做出的结果是这样的,汗!!!(问题还是解方程那需要更高的精度) *
************
*** ***
*** **
** *
** **
* *
** *
** *
* **
** *
* *
**
** *
* *
** *
** *
** *
**
*** *
*** *
******** public class JJ { public static int evaluations = 0;
public static double constant = 0.017453292519943295769236907684886; public static double func(double x) {
double result; result = Math.abs(Math.sin(0.017453292519943295769236907684886 * x)
* (x / 90)); evaluations++; return result;
} public static void prints(int start, int end, int width, int height) {
/**
* @unit 是每次x增加的单位,为了使图形在0-width范围内
*/
double widthUnit = (end - start) / width;/**
* 为了使最高高度达到height 我们需要进行缩小或者放大 首先要计算出最高能达到的高度
* 要先sin(0.0174....*x)*(x/90)并不是单增函数 求导得到:sin(T*x) + Tx(cos(TX)) = 0
* ==>tan(Tx) = -Tx (tan曲线与y=-x相交) ==>Tx 大致的范围是(PI< Tx <2/3PI)
*/
/*找到最大的值topY 以及对应的topX*/
int topY = 0;
double result = 0;
int topX = 0;
for (int x = 90; x < 180; x++) {
if (func(x) >= func(x + 1)) {
result = func(x);
topY = (int) (func(x) * height);
topX = x;
break;
} }
System.out.println("topY is " + topY);
System.out.println("result is " + result);/**
* func(x)*height <21 * 所以应该从这里入手,把21作为最高点,然后x=116作为中心,将x分布两边
*/ /**
* 缩放的单位:
*/
double unit = (double) (end - start) / (double) width; /*缩放后,其最大值对应的x坐标*/
int mid = (int) (topX / unit); for (int i = 0; i <= width; i++) {
if (i == mid) System.out.print("*");
else
System.out.print(" ");
}
System.out.println(); /*从上往下输出*/
for (int y = topY; y >= 0; y--) {
/*每次输出一个字符,对应的x坐标应该只加上缩放的单位,只移动movement*/
double movement = start; for (int x = start; x < width; x++) {
/*该x坐标对应的y取整后,将其放到相应的行数去(输出*)*/
if ((int) (height * func(movement)) >= y && (int) (height * func(movement)) < y + 1) { System.out.print("*");
} else {
System.out.print(" ");
}
/*没输出一个字符 x 坐标都加上一个unit*/
movement += unit;
}
System.out.println();
} } public static void main(String[] args) {
prints(0, 180, 80, 18); }}