Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. //importuję bibliotekę Math (potrzebna do funkcji sqrt, cos, sin)
  2. import java.lang.Math;
  3.  
  4. class Complex {
  5.     double Re, Im;
  6.    
  7.     public double getRe()
  8.     {
  9.         return Re;
  10.     }
  11.    
  12.     public double Im()
  13.     {
  14.         return Im;
  15.     }
  16.    
  17.     //zadanie 1
  18.     //wyświetlanie postaci kartezjańskiej
  19.     void wyswietlLiczbe()
  20.     {
  21.         System.out.println(Re + " + " + Im + "i");
  22.     }
  23.    
  24.     //zadanie 2
  25.     //obliczanie argumentu głównego
  26.     double obliczArgument()
  27.     {
  28.         double modul = Math.sqrt(Re*Re + Im*Im);
  29.        
  30.         if (Re >= 0 && Im >= 0)
  31.         {
  32.             return Math.asin(Im / modul);
  33.         }
  34.         if (Re <= 0 && Im >= 0)
  35.         {
  36.             return Math.acos(Re / modul);
  37.         }
  38.         if (Re > 0 && Im <= 0)
  39.         {
  40.              return Math.asin(Im / modul);
  41.         }
  42.         if (Re <= 0 && Im <= 0)
  43.         {
  44.             return (-1)*Math.acos(Re / modul);
  45.         }
  46.         return 0.0;
  47.     }
  48.    
  49.     //zadanie 3
  50.     //ododawanie i odejmowanie licb zespolonych
  51.     //dodawanie / odejmowanie liczb zespolonych odbywa się przez dodanie/odjęcie
  52.     //osobno części rzeczywistych i urojonych
  53.     //link do materiałów: https://obliczone.pl/wzory-i-w%C5%82asno%C5%9Bci/liczby-zespolone
  54.     Complex dodawanie(Complex liczba)
  55.     {
  56.         double re = this.Re + liczba.Re;
  57.         double im = this.Im + liczba.Im;
  58.         return new Complex(re, im);
  59.     }
  60.    
  61.     Complex odejmowanie(Complex liczba)
  62.     {
  63.         double re = this.Re - liczba.Re;
  64.         double im = this.Re - liczba.Re;
  65.         return new Complex(re, im);
  66.     }
  67.    
  68.     Complex (double Re, double Im) {
  69.         this.Re = Re;
  70.         this.Im = Im;
  71.     }
  72. }
  73.  
  74. public class main{
  75.      public static void main(String []args){
  76.         Complex liczba1 = new Complex(0, 1);
  77.         liczba1.obliczArgument();
  78.      }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement