Emamof
/*
Thae name of Allh 
THis Class is written to represent the complex Noa nd to get the fesabilete to deal it as data type 

By: Mohamed Ahmed Al Emam
3rd CSE in 12-3-2009

note :this clas is packge name cmplx 
*/package cmplx;
public class cmplx {
/**
* class members
<>
r== real part of complex No.
i== imaginary part of complex No.
<>
m== magnitude of the complex No.
a== phase or angle of complex No.
*/
public double r,i,m,a;
//constructor code  start ====================================
public cmplx(double x,double y,boolean z) {
if (z) {
r=x;
i=y;
m=Math.pow(((r*r)+(i*i)), .5);
a=Math.atan(y/x);
}
else {
m=x;
a=y;
r=(m*Math.cos(a));
i=(m*Math.sin(a));
}
}
// this is an empty constructor 
public cmplx() {
}
//constructor code  end  =============================
//methods Code Start 
/**
this method will perform the addition operation ====================
*/
public static cmplx add (cmplx no1,cmplx no2) {
return new cmplx ((no1.r+no2.r),(no1.i+no2.i),true);
}
//add method code is end =========================================
/**
this method will perform the subtraction operation===================== 
*/
public static cmplx sub (cmplx no1,cmplx no2) {
return new cmplx ((no1.r-no2.r),(no1.i-no2.i),true); }
//sub method code is end ========================================
/**
this method will perform the Multiplication operation================
*/
public static cmplx mul (cmplx no1,cmplx no2) {
return new cmplx ((no1.m*no2.m),(no1.a+no2.a),false);
}
//Multiplication method code is end ============================
/**
this method will perform the Divesion operation============================= 
*/
public static cmplx div (cmplx no1,cmplx no2) {
return new cmplx ((no1.m/no2.m),(no1.a-no2.a),false);
}
//Divesion method code is end ======================================
/**
this method will return with the real part of the No========================== 
*/
public static double getReal(cmplx no1) {
return no1.r;
}
//getReal method code is end =============================
/**
this method will return with the real part of the No========================= 
*/
public static double getIm(cmplx no1) {
return no1.i;
}
//getIm method code is end ==================================
/**
this method will return with the magnetude  of the No============= 
*/
public static double getMag(cmplx no1) {
return no1.m;
}
//getMag method code is end ================================
/**
this method will return the angle Phase of the No============================ 
*/
public static double getAng(cmplx no1) {
return no1.a;
}
}

كنت قد عملت على انشاء هذه الـ class لحل مشكلة التعامل مع القيم التخيلية في المعادلات الناتجة عن تحليل الدوائر الكهربية المحتوية على عناصر سعوية او ملفات وتمكنت باستخدامها من حل تطبيقين قد كانا طلبا من قبل .

 

Labels: , edit post
1 Response
  1. Mohamed Atia Says:

    kont te7wel te3mel overload lel operators