-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionDivide.cpp
More file actions
28 lines (24 loc) · 1.17 KB
/
FunctionDivide.cpp
File metadata and controls
28 lines (24 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "FunctionDivide.h"
FunctionDivide::FunctionDivide(SharedPtr<Function> up, SharedPtr<Function> down):downFunction(down), upFunction(up)
{
Function::MargeVatiable(up->Variables(), down->Variables());
}
SharedPtr<Function> FunctionDivide::DeriveBy(const std::string &variable) const
{
SharedPtr<Function> upDerive = this->upFunction->DeriveBy(variable);
SharedPtr<Function> downDerive = this->downFunction->DeriveBy(variable);
SharedPtr<Function> newUpLeftDerive = new FunctionMulti(upDerive,this->downFunction);
SharedPtr<Function> newUpRigthDerive = new FunctionMulti(downDerive,this->upFunction);
SharedPtr<Function> newUp = new FunctionDiffrence(newUpLeftDerive,newUpRigthDerive);
SharedPtr<Function> newDown = new FunctionMulti(this->downFunction,this->downFunction);
return new FunctionDivide(newUp,newDown);
}
double FunctionDivide::Evaluate(const std::map<std::string, double> &variables) const
{
double upSum = this->upFunction->Evaluate(variables);
double downSum = this->downFunction->Evaluate(variables);
if(downSum==0){
std::cout<<"Error: out of range!/n";
}
return upSum/downSum;
}