Fortran Coder

楼主: 王培杰
打印 上一主题 下一主题

[特殊函数] 求勒让德多项式的零点,调试失败,求解哪里错了

[复制链接]

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

水王勋章元老勋章热心勋章

楼主
发表于 2014-3-20 16:44:45 | 显示全部楼层
正确的做法应该是转换为计算伴随矩阵的特征值
贴一个matlab代码:
function [x, w] = GaussLegendre_2(n)
% As you can see, the code consists of 2 blocks:
% 1: construct a symmetrical companion matrix
% 2: determine the (real) eigenvalues (i.e. the roots of the polynomial).
% It can produce the correct abscissas and weights, for any value n>=2.
%
% input: n ---- number of intergrate points
%
% output: x --- GaussLegendre intergrate point
%         w --- GaussLegendre intergrate weight
%
i = 1:n-1;
a = i./sqrt(4*i.^2-1);
CM = diag(a,1) + diag(a,-1);
[V L] = eig(CM);
[x ind] = sort(diag(L));
V = V(:,ind)';
w = 2 * V(:,1).^2;
return
end

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

水王勋章元老勋章热心勋章

沙发
发表于 2014-3-27 21:49:47 | 显示全部楼层
王培杰 发表于 2014-3-21 22:42
终于成功了!谢谢@chuxf,帮我解决了很多问题。第二次编程终于完成了高斯勒让德积分法。一下是最后的完整 ...

lz可以尝试把多项式阶次提升到50以上,若不采用计算特征值的办法,计算出来的积分点和权系数是不正确的
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-2 20:15

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表