How to use fsolve to solve all the equations?
古いコメントを表示
%For the following equations want to solve all of its solutions, using solve to solve the time is too long, but using fsolve to solve I wrote the following program, but feel that the solution is not quite right, given too many results
function [F] = modulation_equation(X)
a=X(1);
c=X(2);
F(1)= 0.1096622461e0 * a ^ 6 - 0.4223705634e-1 * a ^ 8 + 0.4066962405e-2 * a ^ 10 - 0.1613995833e-2 * c ^ 2 * a ^ 4 + 0.5938649525e-5 * c ^ 4 * a ^ 2 - 0.3163847188e7 * c ^ 2 * a ^ 8 + 0.8689234851e5 * c ^ 4 * a ^ 6 + 0.9705023202e3 * c ^ 6 * a ^ 4 - 0.8469105945e0 * c ^ 2 * a ^ 6 + 0.1203014830e-1 * c ^ 4 * a ^ 4 - 0.4506937871e-4 * c ^ 6 * a ^ 2 + 0.8083313632e1 * c ^ 8 * a ^ 2;
F(2)= -0.6970477491e12 * a ^ 12 + 0.1914345842e11 * c ^ 2 * a ^ 10 + 0.2138367102e9 * c ^ 4 * a ^ 8 + 0.1815447799e7 * c ^ 6 * a ^ 6 - 0.5120907418e3 * c ^ 8 * a ^ 4 + 0.1885489314e1 * a ^ 2 * c ^ 10 - 0.8368566306e4 * c ^ 2 * a ^ 8 - 0.4108305749e5 * c ^ 4 * a ^ 6 + 0.6065237395e3 * c ^ 6 * a ^ 4 + 0.1220234699e5 * c ^ 2 * a ^ 6 - 0.1795926849e3 * c ^ 4 * a ^ 4 + 0.6608059271e0 * c ^ 6 * a ^ 2 - 0.2232435902e1 * c ^ 8 * a ^ 2;
end
clear
x_range = -1:0.01:1; % 定义 a 的初值范围
y_range = -1:0.05:1; % 定义 c 的初值范围
sol = []; % 用于存储唯一解的矩阵
options = optimoptions('fsolve', 'Display', 'off'); % 设置 fsolve 参数,不显示输出
% 遍历区间中的初值组合
for j = x_range
for i = y_range
x0 = [j, i]; % 当前初始点
try
% 尝试使用 fsolve 求解
[X_sol, fval, exitflag] = fsolve(@modulation_equation, x0, options);
if exitflag > 0 % 仅当成功求解时处理
% 检查新解是否已存在于 sol 中(判断相似解)
if isempty(sol) || all(vecnorm(sol - X_sol, 2, 2) > 1e-2)
sol = [sol; X_sol]; % 添加唯一解 (a, c) 作为一行
end
end
catch
% 如果 fsolve 失败,跳过该点
continue
end
end
end
sol = unique(sol, 'rows', 'stable');
sol1= sol(sol(:, 1) ~= 0 & sol(:, 2) ~= 0, :);
sol2=sqrt(sol1(:, 1).^2 + sol1(:, 2).^2);
sol3=sort(unique(sol2,'rows', 'stable'))
1 件のコメント
Alex Sha
2024 年 11 月 18 日
some thing wrong? the exact solution is: a=0, c=0
採用された回答
その他の回答 (1 件)
カテゴリ
ヘルプ センター および File Exchange で Systems of Nonlinear Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!