複素数 – プログラミング – Home

通知
すべてクリア

[解決済] 複素数


夏男
 夏男
(@夏男)
ゲスト
結合: 20年前
投稿: 7
Topic starter  

はじめまして。いきなりですみませんが下記のプログラムを完成を
お願いします。複素数において、実部と虚部をメンバ変数としたものは
何度もみましたが、絶対値rと偏角thetaを変数にしたこれは
わかりませんでした。.......の部分をプログラムに書き換えるみたいです。
なお、.......の行数に意味はないとのこてです。
よろしくお願いします。

#include <iostream>
#include <cmath>
using namespace std;

class complex {
double r, theta; // r: absolute value,
// theta: argument
public:
complex() {r = 0.0, theta = 0.0;}
complex(double rr, double tt)
{ r = rr; theta = tt; }
void get_r_theta(double &rr, double &tt)
{ rr = r; tt = theta; }
complex operator+(complex ob2);
complex operator-(complex ob2);
complex operator*(complex ob2);
complex operator/(complex ob2);
complex operator=(complex ob2);
};
complex complex::operator+(complex ob2)
{
complex temp;
...................
...................
...................
return temp;
}
complex complex::operator-(complex ob2)
{
complex temp;
...................
...................
...................
return temp;
}
complex complex::operator*(complex ob2)
{
complex temp;
...................
...................
...................
return temp;
}
complex complex::operator/(complex ob2)
{
complex temp;
...................
...................
...................
return temp;
}
complex complex::operator=(complex ob2)
{
...................
...................
...................
return *this;
}

int main()
{
complex c1(1.0, 3,1416*0.33),
c2(2.0, 3,1416*0.2),
c3;
double rr, tt;

c3 = c1 + c2;
c3.get_r_theta(rr, tt);
cout << (c1+c2) r: << rr << , theta: << tt << endl;

c3 = c1 - c2;
c3.get_r_theta(rr, tt);
cout << (c1-c2) r: << rr << , theta: << tt << endl;

c3 = c1 * c2;
c3.get_r_theta(rr, tt);
cout << (c1*c2) r: << rr << , theta: << tt << endl;

c3 = c1 / c2;
c3.get_r_theta(rr, tt);
cout << (c1/c2) r: << rr << , theta: << tt << endl;

c3 = c2;
c3.get_r_theta(rr, tt);
cout << (c3=c2) r: << rr << , theta: << tt << endl;
}


引用未解決
トピックタグ
Blue
 Blue
(@Blue)
ゲスト
結合: 21年前
投稿: 1467
 

C++どうこうより、掲示板の使い方を学んだほうがいいです。
http://www.hyuki.com/writing/techask.html

> いきなりですみませんが下記のプログラムを完成をお願いします。
それで、あなたのためになるのでしょうか?
課題はなんのためにあるのでしょうか?そんなこと誰でもわかりますよね?


返信引用
夏男
 夏男
(@夏男)
ゲスト
結合: 20年前
投稿: 7
Topic starter  

すみません、急いでいるのでつい。。。
PCの具合が悪く、コマンドプロンプトを用いてもコンパイルできなく
なったためお願いしました。
ちなみに私の考えた結果は以下です。
complex complex::operator+(complex ob2)
{
complex temp;

temp.r = r + ob2.r;
temp.theta = theta + ob2.theta;

return temp;
}

complex complex::operator-(complex ob2)
{
complex temp;

r = -r;
theta = -theta;

return temp;
}

complex complex::operator*(complex ob2)
{
complex temp;

temp.r = r * ob2.r - theta * ob2.theta;
temp.theta = r * ob2.theta + theta * ob2.r;

return temp;
}

complex complex::operator/(complex ob2)
{
complex temp;

temp.r = r / ob2.r;
temp.theta = theta / ob2.theta;

return temp;
}

complex complex::operator=(complex ob2)
{
r = ob2.r;
theta = ob2.theta;

return *this;
}


返信引用
夏男
 夏男
(@夏男)
ゲスト
結合: 20年前
投稿: 7
Topic starter  

急いでいたとはいえルールを無視し申し訳ありません。
この掲示板を見て不快に思う方すみません。
時間は少ないですがなんとか自分で解決してみます。
忠告してくれた方ありがとうございました。


返信引用
夏男
 夏男
(@夏男)
ゲスト
結合: 20年前
投稿: 7
Topic starter  

解決


返信引用
Blue
 Blue
(@Blue)
ゲスト
結合: 21年前
投稿: 1467
 

解決しちゃったけど。。。。

> double r, theta; // r: absolute value,
> // theta: argument
これって、絶対値と偏角で複素数を表してるんですよね?

各operatorの計算の仕方これであってんですかねぇ?

極形式だと、
z1 = r1( cosθ1 + i * sinθ1 )
z2 = r2( cosθ2 + i * sinθ2 )

だから、掛け算なんか r = r1 * r2, θ = θ1 + θ2 だし。。。
(もう計算できんw)


返信引用
επιστημη
 επιστημη
(@επιστημη)
ゲスト
結合: 22年前
投稿: 600
 

一旦直交座標系: x+yi に変換したほが楽ちゃうかな。
てゆっか、なんで std::complex<double> 使わんのや…宿題なら自分でおやんなさい。


返信引用

返信する

投稿者名

投稿者メールアドレス

タイトル *

プレビュー 0リビジョン 保存しました
共有:
タイトルとURLをコピーしました