小编Clo*_*ife的帖子

三次样条程序

我正在尝试编写一个三次样条插值程序.我编写了程序,但图表没有正确显示.样条曲线使用自然边界条件(起始/结束节点处的第二个衍生物为0).代码在Matlab中,如下所示,

clear all
%Function to Interpolate
k = 10;                    %Number of Support Nodes-1
xs(1) = -1;
for j = 1:k
    xs(j+1) = -1 +2*j/k;   %Support Nodes(Equidistant)
end;
fs = 1./(25.*xs.^2+1);     %Support Ordinates
x = [-0.99:2/(2*k):0.99];  %Places to Evaluate Function
fx = 1./(25.*x.^2+1);      %Function Evaluated at x

%Cubic Spline Code(Coefficients to Calculate 2nd Derivatives)

f(1) = 2*(xs(3)-xs(1));
g(1) = xs(3)-xs(2);
r(1) = (6/(xs(3)-xs(2)))*(fs(3)-fs(2)) + (6/(xs(2)-xs(1)))*(fs(1)-fs(2));
e(1) = 0;

for i = 2:k-2
    e(i) = xs(i+1)-xs(i);
    f(i) = 2*(xs(i+2)-xs(i));
    g(i) = xs(i+2)-xs(i+1); …
Run Code Online (Sandbox Code Playgroud)

matlab interpolation matrix spline

6
推荐指数
1
解决办法
3万
查看次数

循环打印

我有以下文件我试图操纵.

 1  2 -3 5  10  8.2
 5  8  5 4  0   6
 4  3  2 3 -2   15
 -3 4  0 2  4   2.33
 2  1  1 1  2.5 0
 0  2  6 0  8   5
Run Code Online (Sandbox Code Playgroud)

该文件只包含数字.

我正在尝试编写一个程序来相互减去行并将结果打印到文件中.我的程序在下面,dtest.txt是输入文件的名称.该计划的名称是make_distance.py.

from math import *

posnfile = open("dtest.txt","r")
posn = posnfile.readlines()
posnfile.close()

for i in range (len(posn)-1):
    for j in range (0,1):
        if (j == 0):
            Xp = float(posn[i].split()[0])
            Yp = float(posn[i].split()[1])
            Zp = float(posn[i].split()[2])

            Xc = float(posn[i+1].split()[0]) …
Run Code Online (Sandbox Code Playgroud)

python printing for-loop

0
推荐指数
1
解决办法
197
查看次数

标签 统计

for-loop ×1

interpolation ×1

matlab ×1

matrix ×1

printing ×1

python ×1

spline ×1