-
Lenguaje
Java usando Swing
-
Descripción
Obtener el seno de un ángulo, la cual está dada por la función:
Sen x = (x - x³/3! + x⁵5/5! - x⁷/7! + ...)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SerieParaObtenerSeno extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private JLabel label_exponente, label_factorial, label_termino;
private JButton button;
public Algoritmo() {
label_exponente = new JLabel("", JLabel.RIGHT);
label_factorial = new JLabel("", JLabel.RIGHT);
label_termino = new JLabel("", JLabel.RIGHT);
button = new JButton("Procesar");
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JPanel panel, subpanel;
panel = new JPanel(new FlowLayout());
panel.add(button);
pane.add(panel);
panel = new JPanel(new BorderLayout());
subpanel = new JPanel(new GridLayout(3, 1));
subpanel.add(new JLabel("Valor de exponente:"));
subpanel.add(new JLabel("Valor de factorial:"));
subpanel.add(new JLabel("Valor de termino:"));
panel.add(subpanel, BorderLayout.WEST);
subpanel = new JPanel(new GridLayout(3, 1));
subpanel.add(label_exponente);
subpanel.add(label_factorial);
subpanel.add(label_termino);
panel.add(subpanel);
pane.add(panel, BorderLayout.SOUTH);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
int n;
double exponente, factorial, sen_x, termino, x;
if(i==1)
{
exponente=1;
factorial=x;
termino=x;
}
else
{
exponente=exponente+2;
factorial=factorial*x*x;
termino=Math.pow(x,exponente)/factorial;
}
if(i%2==0)
sen_x=sen_x-termino;
else
sen_x=sen_x+termino;
label_exponente.setText(String.valueOf(exponente));
label_factorial.setText(String.valueOf(factorial));
label_termino.setText(String.valueOf(termino));
pack();
}
public static void main(String[] args) {
new Algoritmo().setVisible(true);
}
}
import java.awt.event.*;
import javax.swing.*;
public class SerieParaObtenerSeno extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private JLabel label_exponente, label_factorial, label_termino;
private JButton button;
public Algoritmo() {
label_exponente = new JLabel("", JLabel.RIGHT);
label_factorial = new JLabel("", JLabel.RIGHT);
label_termino = new JLabel("", JLabel.RIGHT);
button = new JButton("Procesar");
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
JPanel panel, subpanel;
panel = new JPanel(new FlowLayout());
panel.add(button);
pane.add(panel);
panel = new JPanel(new BorderLayout());
subpanel = new JPanel(new GridLayout(3, 1));
subpanel.add(new JLabel("Valor de exponente:"));
subpanel.add(new JLabel("Valor de factorial:"));
subpanel.add(new JLabel("Valor de termino:"));
panel.add(subpanel, BorderLayout.WEST);
subpanel = new JPanel(new GridLayout(3, 1));
subpanel.add(label_exponente);
subpanel.add(label_factorial);
subpanel.add(label_termino);
panel.add(subpanel);
pane.add(panel, BorderLayout.SOUTH);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
int n;
double exponente, factorial, sen_x, termino, x;
if(i==1)
{
exponente=1;
factorial=x;
termino=x;
}
else
{
exponente=exponente+2;
factorial=factorial*x*x;
termino=Math.pow(x,exponente)/factorial;
}
if(i%2==0)
sen_x=sen_x-termino;
else
sen_x=sen_x+termino;
label_exponente.setText(String.valueOf(exponente));
label_factorial.setText(String.valueOf(factorial));
label_termino.setText(String.valueOf(termino));
pack();
}
public static void main(String[] args) {
new Algoritmo().setVisible(true);
}
}