Open CASCADE学习|非线性方程组

非线性方程组是一组包含非线性数学表达式的方程,即方程中含有未知数的非线性项。解这类方程组通常比解线性方程组更为复杂和困难。

非线性方程组在很多领域都有应用,例如物理学、工程学、经济学等。解决非线性方程组的方法有很多种,包括数值方法和解析方法。数值方法是通过迭代或搜索来找到近似解,而解析方法则是通过对方程进行变换或展开来找到精确解。

在处理非线性方程组时,需要注意一些问题,例如初始值的选择、解的唯一性和稳定性等。同时,也需要根据具体问题的特点选择合适的求解方法。

OpenCASCADE提供了非线性方程组的类math_FunctionSet,下面给出一个具体的例子来说明其的用法。

待求解方程组:

从几何上看其解就是圆心在原点,半径为2的圆与曲线的交点:

cpp 复制代码
#include <math_FunctionSet.hxx>
#include <math_FunctionSetWithDerivatives.hxx>
#include <math_FunctionSetRoot.hxx>
​
class MyFunctionSet : public math_FunctionSetWithDerivatives
{
public:
    virtual Standard_Integer NbVariables() const
{
        return 2;
    }
​
    virtual Standard_Integer NbEquations() const
{
        return 2;
    }
​
    virtual Standard_Boolean Value(const math_Vector& X, math_Vector& F)
{
        F(1) = X(1) * X(1) + X(2) * X(2) - 4.0;
        F(2) = Pow(M_E, X(1)) + X(2) - 1.0;
        return Standard_True;
    }
​
    virtual Standard_Boolean Derivatives(const math_Vector& X, math_Matrix& D)
{
        // matrix D is Jacobi matrix.
        D(1, 1) = 2.0 * X(1);
        D(1, 2) = 2.0 * X(2);
        D(2, 1) = Pow(M_E, X(1));
        D(2, 2) = 1.0;
        return Standard_True;
    }
​
    virtual Standard_Boolean Values(const math_Vector& X, math_Vector& F, math_Matrix& D)
{
        Value(X, F);
        Derivatives(X, D);
        return Standard_True;
    }
​
private:
};
​
void test()
{
    MyFunctionSet aFunctionSet;
    math_FunctionSetRoot aSolver(aFunctionSet);
    math_Vector aStartingPoint(1, 2);
    // 1. (1.0, 1.0)
    aStartingPoint(1) = 1.0;
    aStartingPoint(2) = 1.0;
    aSolver.Perform(aFunctionSet, aStartingPoint);
    if (aSolver.IsDone())
    {
        aSolver.Dump(std::cout);
    }
​
    // 2. (1.0, -1.0)
    aStartingPoint(1) = 1.0;
    aStartingPoint(2) = -1.0;
    aSolver.Perform(aFunctionSet, aStartingPoint);
    if (aSolver.IsDone())
    {
        aSolver.Dump(std::cout);
    }
}
int main(int argc, char* argv[])
{
    test();
    return 0;
}
​

math_FunctionSetRoot Status = Done

Location value = math_Vector of Length = 2

math_Vector(1) = -1.81626

math_Vector(2) = 0.837368

Number of iterations = 14

math_FunctionSetRoot Status = Done

Location value = math_Vector of Length = 2

math_Vector(1) = 1.00417

math_Vector(2) = -1.72964

Number of iterations = 6

相关推荐
凌肖战7 分钟前
力扣上刷题之C语言实现(数组)
c语言·算法·leetcode
编程版小新7 分钟前
C++初阶:STL详解(四)——vector迭代器失效问题
开发语言·c++·迭代器·vector·迭代器失效
秋夫人34 分钟前
B+树(B+TREE)索引
数据结构·算法
李小星同志36 分钟前
高级算法设计与分析 学习笔记6 B树
笔记·学习
霜晨月c1 小时前
MFC 使用细节
笔记·学习·mfc
小江湖19941 小时前
元数据保护者,Caesium压缩不丢重要信息
运维·学习·软件需求·改行学it
梦想科研社1 小时前
【无人机设计与控制】四旋翼无人机俯仰姿态保持模糊PID控制(带说明报告)
开发语言·算法·数学建模·matlab·无人机
Milo_K1 小时前
今日 leetCode 15.三数之和
算法·leetcode
Darling_001 小时前
LeetCode_sql_day28(1767.寻找没有被执行的任务对)
sql·算法·leetcode
AlexMercer10121 小时前
【C++】二、数据类型 (同C)
c语言·开发语言·数据结构·c++·笔记·算法