두 개의 정적 메서드를 만들었습니다.정적 메서드 그래프 표시
첫 번째 것은 x에 대한 사용자 입력으로부터 f (x)를 찾는 것입니다. 이것은 완료되고 작동합니다.
둘째로 나에게 문제점이있다. x []와 y []의 두 배열에서 점을 그래프로 연결하고 연결한다고 가정합니다. 필자가 플러그인 한 것과 상관없이 동일한 그래프를 계속 제공합니다. 메소드 작성에 익숙하지 않고 Java에서 그래프를 완전히 이해하지 못합니다.
누군가 내가 뭘 잘못하고 있다고 말할 수 있습니까?
감사합니다. 요 메인의 메소드를 호출하지 않는
import java.util.*;
public class dummy {
public static void main (String args[]) {
Scanner keyboard = new Scanner(System.in);
//ask user for input and store in xi
System.out.println("Please enter a value for x.");
double xi = keyboard.nextDouble();
double f = f(xi); //call f(x) method
System.out.println("The equation is:" + f);
//creating arrays x[] and y[], then filling them with values
int n = 500;
double x[] = new double[n+1];
double y[] = new double[n+1];
for (int i = 1; i <= n; i++) {
x[i] = i/n ;
y[i] = Math.exp(x[i]) * Math.sin(x[i]) - (5*(Math.pow(x[i],3))+2);}
//calling the draw graph method
drawGraph(x,y);
}
//first method to find f(x) from user input X
public static double f(double xi){
double a = xi;
double b = Math.exp(a) * Math.sin(a) - (5*(Math.pow(a,3))+2);
return b;}
//second method to draw the graph
public static void drawGraph(double x[],double y[]){
StdDraw.setXscale(-10, 10);
StdDraw.setYscale(-10, 10);
StdDraw.setPenRadius(.01);
StdDraw.setPenColor(StdDraw.BLUE);
for (int i=1; i<=500; i++){
StdDraw.line(x[i-1], y[i-1], x[i], y[i]);
StdDraw.point(x[i],y[i]);}
}
}
같은 방법 somenthing를 호출 시도해야 운영. 예 : 'main'에 두 개의 배열'x'와'y'를 만들고'main'에'drawGraph (x, y);'를 놓습니다. – khelwood
@khelwood 고마워요! 이제는 그래프의 절반 만 그려보고 오류가 발생하는 문제가 있습니다. 어떤 제안? 새 코드로 답변을 게시했습니다. –