Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //importuję bibliotekę Math (potrzebna do funkcji sqrt, cos, sin)
- import java.lang.Math;
- class Complex {
- double Re, Im;
- public double getRe()
- {
- return Re;
- }
- public double Im()
- {
- return Im;
- }
- //zadanie 1
- //wyświetlanie postaci kartezjańskiej
- void wyswietlLiczbe()
- {
- System.out.println(Re + " + " + Im + "i");
- }
- //zadanie 2
- //obliczanie argumentu głównego
- double obliczArgument()
- {
- double modul = Math.sqrt(Re*Re + Im*Im);
- if (Re >= 0 && Im >= 0)
- {
- return Math.asin(Im / modul);
- }
- if (Re <= 0 && Im >= 0)
- {
- return Math.acos(Re / modul);
- }
- if (Re > 0 && Im <= 0)
- {
- return Math.asin(Im / modul);
- }
- if (Re <= 0 && Im <= 0)
- {
- return (-1)*Math.acos(Re / modul);
- }
- return 0.0;
- }
- //zadanie 3
- //ododawanie i odejmowanie licb zespolonych
- //dodawanie / odejmowanie liczb zespolonych odbywa się przez dodanie/odjęcie
- //osobno części rzeczywistych i urojonych
- //link do materiałów: https://obliczone.pl/wzory-i-w%C5%82asno%C5%9Bci/liczby-zespolone
- Complex dodawanie(Complex liczba)
- {
- double re = this.Re + liczba.Re;
- double im = this.Im + liczba.Im;
- return new Complex(re, im);
- }
- Complex odejmowanie(Complex liczba)
- {
- double re = this.Re - liczba.Re;
- double im = this.Re - liczba.Re;
- return new Complex(re, im);
- }
- Complex (double Re, double Im) {
- this.Re = Re;
- this.Im = Im;
- }
- }
- public class main{
- public static void main(String []args){
- Complex liczba1 = new Complex(0, 1);
- liczba1.obliczArgument();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement