求用C++语言实现cos(α1+α2+α3+……+αn) = 和sin(α1+α2+α3+……+αn) =的分解cos(α+β) = cosαcosβ- sinαsinβ,sin(α+β) = sinαcosβ+ cosαsinβ cos(α+β+γ) = cos(α+(β+γ)) = cosαcos(β+γ) - sinαsin(β+γ) =cosαcosβcosγ-c

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/17 08:53:11
求用C++语言实现cos(α1+α2+α3+……+αn)=和sin(α1+α2+α3+……+αn)=的分解cos(α+β)=cosαcosβ-sinαsinβ,sin(α+β)=sinαcosβ+co

求用C++语言实现cos(α1+α2+α3+……+αn) = 和sin(α1+α2+α3+……+αn) =的分解cos(α+β) = cosαcosβ- sinαsinβ,sin(α+β) = sinαcosβ+ cosαsinβ cos(α+β+γ) = cos(α+(β+γ)) = cosαcos(β+γ) - sinαsin(β+γ) =cosαcosβcosγ-c
求用C++语言实现cos(α1+α2+α3+……+αn) = 和sin(α1+α2+α3+……+αn) =的分解
cos(α+β) = cosαcosβ- sinαsinβ,sin(α+β) = sinαcosβ+ cosαsinβ
cos(α+β+γ) = cos(α+(β+γ)) = cosαcos(β+γ) - sinαsin(β+γ) =cosαcosβcosγ-cosαsinβsinγ- sinαsinβcosγ- sinαcosβsinγ,
sin(α+β+γ) = sin(α+(β+γ)) = sinαcos(β+γ) + cosαsin(β+γ) =sinαcosβcosγ-sinαsinβsinγ+ cosαsinβcosγ+ cosαcosβsinγ

求用C++语言实现cos(α1+α2+α3+……+αn) = 和sin(α1+α2+α3+……+αn) =的分解cos(α+β) = cosαcosβ- sinαsinβ,sin(α+β) = sinαcosβ+ cosαsinβ cos(α+β+γ) = cos(α+(β+γ)) = cosαcos(β+γ) - sinαsin(β+γ) =cosαcosβcosγ-c
#include
#include
#include
using namespace std;
#define SIN_FN 1
#define COS_FN 2
class Expression
{
public:
Expression();
Expression(int fn,const string* args,int n_args);
void varVecToString(string& out);
void varComboToString(string& out);
void toString(string& out,bool omit_positive_sign);
Expression* calculate();
public:
bool is_positive;
struct Var
{
int fn;
string name;
};
vector var_vec;
int combo_fn;
vector var_combo;
Expression* prev;
Expression* next;
protected:
void varToString(int i,string& output);
};
static string* s_sin_prefix = NULL;
static string* s_cos_prefix = NULL;
int main()
{
s_sin_prefix = new string("sin");
s_cos_prefix = new string("cos");
string str;
int fn;
int n_args;
string* args = NULL;
// read the function
retry_fn:
coutprev = this;
new_exp->next = next;
next = new_exp;
new_exp->is_positive = is_positive;
new_exp->var_vec = var_vec;
new_exp->var_combo = var_combo;
if (combo_fn == SIN_FN)
{
var.fn = COS_FN;
var.name = var_combo[0];
new_exp->var_vec.push_back(var);
new_exp->combo_fn = SIN_FN;
new_exp->var_combo.erase(new_exp->var_combo.begin());
combo_fn = COS_FN;
var_combo.erase(var_combo.begin());
var.fn = SIN_FN;
var_vec.push_back(var);
}
else
{
new_exp->is_positive = !(new_exp->is_positive);
var.fn = SIN_FN;
var.name = var_combo[0];
new_exp->var_vec.push_back(var);
new_exp->combo_fn = SIN_FN;
new_exp->var_combo.erase(new_exp->var_combo.begin());
combo_fn = COS_FN;
var_combo.erase(var_combo.begin());
var.fn = COS_FN;
var_vec.push_back(var);
}
return new_exp;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// 我用GCC编译的,你试试你的编译器能不能通过,另外自己根据需要改main函数
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////