miércoles, 22 de mayo de 2024

Metodo de Biseccion - Metodos Numericos con Java Netbeans

import javax.swing.table.DefaultTableModel;

public class frmMetodo2 extends javax.swing.JFrame {

DefaultTableModel model = new DefaultTableModel();

DefaultTableModel model2 = new DefaultTableModel();

DefaultTableModel model3 = new DefaultTableModel();

    public frmMetodo2() {

        initComponents();

        tblI.setModel(model);

        tblI2.setModel(model2);

        tblX.setModel(model3);

        String titu[] = {"X","f(x)"};

        String titu2[] = {"X0","X1"};

        String titu3[] = {"X"};

        model.setColumnIdentifiers(titu);

        model2.setColumnIdentifiers(titu2);

        model3.setColumnIdentifiers(titu3);

    }

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    double i,f,x0,f0;
    i=0.0;
    f=0.0;
    x0=0;
    f0=0;
    String dat[] = new String[2];
    String dat2[] = new String[2];
    for(i=-50;i<50;i++){
        f = Math.exp(i)-2*i-2;
        dat[0] = i + "";
        dat[1] = f + "";
        model.addRow(dat);
        if (f*f0<0) {
            dat2[0] = x0+"";
            dat2[1] = i + "";
            model2.addRow(dat2);
        }
        x0=i;
        f0=f;
        }
 }                                        
private void metodoBi(double x0,double x1) {
    double xm,f0,fm;
    double e;
    String X[] = new String[1];
    xm = (x0 + x1)/2;
    e = Math.abs((xm-x0)/xm);
    if (e>0.01) {
        f0 = Math.exp(x0)-2*x0-2;
        fm = Math.exp(xm)-2*xm-2;
        if (f0*fm<0) {
            metodoBi(x0,xm);
        } else {
            metodoBi(xm,x1);
        }
    } else {
        X[0] = xm+"";
        model3.addRow(X);
    }
 }
private void btnCalcActionPerformed(java.awt.event.ActionEvent evt) {                                        
        int n = model2.getRowCount();
        if (n>0) {
            double x0 = Double.parseDouble(model2.getValueAt(0, 0).toString());
            double x1 = Double.parseDouble(model2.getValueAt(0, 1).toString());
            metodoBi(x0,x1);
            x0 = Double.parseDouble(model2.getValueAt(1, 0).toString());
            x1 = Double.parseDouble(model2.getValueAt(1, 1).toString());
            metodoBi(x0,x1);
        }
    }
}
minuvasoft10@gmail.com


miércoles, 15 de mayo de 2024

Mini Software de Recibo con VB .Net 2022 y Excel 365 + Impresion + Codigo Fuente

De la caja de Herramientas agregar PrintDocument1 y PrintPreviewDialog1.

Imports System.Runtime.InteropServices.JavaScript.JSType

Imports Microsoft.Office.Interop

Public Class frmGrid3

    Dim Aplicacion As Excel.Application

    Dim Libro As Excel.Workbook

    Dim hoja As Excel.Worksheet

    Private Sub frmGrid3_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        cargarLibro()

    End Sub

    Private Sub cargarLibro()

        DataGridView1.ColumnCount = 3

        DataGridView1.Columns(0).Name = "Bar Code"

        DataGridView1.Columns(1).Name = "Producto"

        DataGridView1.Columns(2).Name = "Precio"

        DataGridView1.Columns(1).Width = 200

        Try

            Aplicacion = New Excel.Application

            Libro = Aplicacion.Workbooks.Open("C:\Users\miky mouse\OneDrive\ejemplo25.xlsx")

            hoja = Libro.Worksheets(2)

        Catch ex As Exception

            closeL()

            MsgBox("Error " + ex.ToString())

        End Try

    End Sub

    Private Sub closeL()

        Libro.Close()

        Aplicacion.Quit()

    End Sub

Private Sub frmGrid3_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed

        Libro.Close()

        Aplicacion.Quit()

    End Sub

Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown

        Dim bc As String

        Dim dato(3) As String

        Dim cad As String

        Dim j As Integer

        j = 0

        cad = " "

        Dim op As Integer

        op = 0

        If e.KeyCode = 13 Then

            bc = TextBox1.Text

            For j = 2 To 24

                If CLng(bc) = CLng(hoja.Cells(j, 1).Value) Then

                    dato(0) = hoja.Cells(j, 1).value

                    dato(1) = hoja.Cells(j, 2).value

                    dato(2) = hoja.Cells(j, 3).value

                    DataGridView1.Rows.Add(dato)

                    op = 1

                    calTot()

                End If

            Next

            If op = 0 Then

                cad = "No tenemos el Producto "

            End If

            MsgBox(cad + bc)

            TextBox1.Text = " "

        End If

    End Sub

    Private Sub calTot()

        Dim S As Double

        Dim pre As Double

        Dim tax As Double

        Dim tot As Double

        Dim n As Integer

        S = 0.00

        pre = 0.00

        n = DataGridView1.RowCount - 1

        For fila = 0 To n

            pre = CDbl(DataGridView1.Item(2, fila).Value)

            S = S + pre

        Next

        S = Math.Round(S, 2)

        lblSub.Text = S.ToString()

        tax = 0.09 * S

        tax = Math.Round(tax, 2)

        lblTax.Text = tax.ToString()

        tot = S + tax

        tot = Math.Round(tot, 2)

        lblTot.Text = tot.ToString()

    End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim n As Integer

        Dim fila2 As Single

        Dim fila3 As Single

        Dim f1, f2, f3 As Single

        Dim cad As String

        Dim cad2 As String

        Dim cad3 As String

        Dim cad4 As String

        Dim cad5 As String

        Dim j As Integer

        fila3 = 1

        fila2 = 1

        Try

            n = DataGridView1.RowCount - 1

            e.Graphics.DrawString("MinuvaMarket", New Font("Arial", 16), New SolidBrush(Color.Black), 50, 50)

            For j = 0 To n

                fila3 = 80 + fila2 * 10

                cad = DataGridView1.Item(1, j).Value

                cad2 = DataGridView1.Item(2, j).Value

                e.Graphics.DrawString(cad, New Font("Arial", 13), New SolidBrush(Color.Black), 20, fila3)

                e.Graphics.DrawString(cad2, New Font("Arial", 13), New SolidBrush(Color.Black), 300, fila3)

                fila2 = fila2 + 2

            Next

            cad3 = "Sub Total.." + lblSub.Text

            cad4 = "Tax........" + lblTax.Text

            cad5 = "Total......" + lblTot.Text

            f1 = fila3 + 20

            f2 = fila3 + 40

            f3 = fila3 + 60

            e.Graphics.DrawString(cad3, New Font("Arial", 13), New SolidBrush(Color.Black), 250, f1)

            e.Graphics.DrawString(cad4, New Font("Arial", 13), New SolidBrush(Color.Black), 250, f2)

            e.Graphics.DrawString(cad5, New Font("Arial", 13), New SolidBrush(Color.Black), 250, f3)

        Catch ex As Exception

            closeL()

            MsgBox("Error " + ex.ToString())

        End Try

    End Sub

Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click

        PrintPreviewDialog1.Document = PrintDocument1

        PrintPreviewDialog1.Width = 500

        PrintPreviewDialog1.Height = 600

        PrintPreviewDialog1.Left = 600

        PrintPreviewDialog1.Top = 150

        PrintPreviewDialog1.ShowDialog()

    End Sub

End Class

download Source Code

Para optimizacion del programa comunicarse a minuvasoft10@gmail.com -- Miguel Nunez




sábado, 11 de mayo de 2024

Calcular Determinante de una Matrix nxn con Java Netbeans + Codigo Fuente


Metodos Numericos, Analisis Numerico.
Clase Deter.java 

public class Deter {

    static final int N = 5;

    static void obtener(double A[][], double temp[][],int p, int q, int n)

    // Metodo para obtener cofactores, p y q es la fila y columna a     // eliminar. 

    {   int i = 0, j = 0;

            for (int row = 0; row < n; row++) {

for (int col = 0; col < n; col++) {

                    if (row != p && col != q) {

temp[i][j++] = A[row][col];

if (j == n - 1) {

                            j = 0;

                            i++;

}

                    }

}

            }

    }

public double deterM(double A[][], int n)

{   double D = 0.0; 

    if (n == 1)

       return A[0][0];

    double temp[][] = new double[N][N];

    int sign = 1;

    for (int f = 0; f < n; f++) {

        obtener(A, temp, 0, f, n);

        D += sign * A[0][f]* deterM(temp, n - 1);

sign = -sign;

    }

    return D;

}

Clase Formulario

import javax.swing.JOptionPane;

import javax.swing.table.DefaultTableModel;

public class frmDeter2 extends javax.swing.JFrame {

    DefaultTableModel model = new DefaultTableModel();

    Deter D = new Deter();

    public frmDeter2() {

        initComponents();

        tblB.setModel(model);

        String titu[] = {"A","B","C"};

        String dato1[] = {"0.55","1.55","2.55"};

        String dato2[] = {"-0.55","3.55","-4.55"};

        String dato3[] = {"5.55","-6.55","2.55"};

        model.setColumnIdentifiers(titu);

        model.addRow(dato1);

        model.addRow(dato2);

        model.addRow(dato3);

    }

    private void cargarM2() {

        model.setRowCount(0);

        String titu[] = {"A","B"};

        String dato1[] = {"0.55","1.55"};

        String dato2[] = {"-0.55","3.55"};

        model.setColumnIdentifiers(titu);

        model.addRow(dato1);

        model.addRow(dato2);

    }

    private void cargarM3() {

        model.setRowCount(0);

        String titu[] = {"A","B","C"};

        String dato1[] = {"0.55","1.55","2.55"};

        String dato2[] = {"-3.55","4.55","-5.55"};

        String dato3[] = {"5.55","-6.55","7.55"};

        model.setColumnIdentifiers(titu);

        model.addRow(dato1);

        model.addRow(dato2);

        model.addRow(dato3);

    }

    private void cargarM4() {

        model.setRowCount(0);

        String titu[] = {"A","B","C","D"};

        String dato1[] = {"0.55","1.55","2.55","6.55"};

        String dato2[] = {"-3.55","4.55","-5.55","7.55"};

        String dato3[] = {"5.55","-6.55","7.55","8.55"};

        model.setColumnIdentifiers(titu);

        model.addRow(dato1);

        model.addRow(dato2);

        model.addRow(dato3);

        model.addRow(dato1);

    }

    private void cargarM5() {

        model.setRowCount(0);

        String titu[] = {"A","B","C","D","E"};

        String dato1[] = {"0.55","1.55","2.55","6.55","2.55"};

        String dato2[] = {"-3.55","4.55","-5.55","7.55","-5.55"};

        String dato3[] = {"5.55","-6.55","7.55","8.55","1.55"};

        String dato4[] = {"5.55","-6.55","7.55","8.55","10.55"};

        String dato5[] = {"-6.55","-6.55","7.55","8.55","1.55"};

        model.setColumnIdentifiers(titu);

        model.addRow(dato1);

        model.addRow(dato2);

        model.addRow(dato3);

        model.addRow(dato4);

        model.addRow(dato5);

    }

private void btnDeterActionPerformed(java.awt.event.ActionEvent evt) {       int i,j;

        double R;

        int N1 = model.getRowCount();

        double A[][]=new double[N1][N1];

        for(i=0;i<N1;i++) {

            for(j=0;j<N1;j++) {

                A[i][j] = Double.parseDouble(model.getValueAt(i, j).toString());

            }

        }

        R = Math.round(D.deterM(A, N1)*1000.0)/1000.0;

        lblR.setText(""+R);

    }                                        

private void cmbEActionPerformed(java.awt.event.ActionEvent evt) {   

    int op = cmbE.getSelectedIndex();

    switch (op){

        case 0: cargarM2(); break;

        case 1: cargarM3(); break;

        case 2: cargarM4(); break;

        case 3: cargarM5(); break;

    }

}  

download source code  

minuvasoft10@gmail.com   


                             


Conectar a MySql con Java Netbeans mediante un Formulario

 Tener agregado en libraries el conector mysql. clase coneBD.java package pktForm12; import java.sql.*; import javax.swing.JOptionPane; publ...