以勒让德多项式为基本函数,在区间[-1,1]上把f(x)=x^4+2x^3展开为广义傅里叶级数,求MATLAB程序
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/02 22:36:12
以勒让德多项式为基本函数,在区间[-1,1]上把f(x)=x^4+2x^3展开为广义傅里叶级数,求MATLAB程序
以勒让德多项式为基本函数,在区间[-1,1]上把f(x)=x^4+2x^3展开为广义傅里叶级数,求MATLAB程序
以勒让德多项式为基本函数,在区间[-1,1]上把f(x)=x^4+2x^3展开为广义傅里叶级数,求MATLAB程序
function f = Legendre(y,k,x0)
% 用勒让德多项式逼近已知函数
% 已知函数:y
% 逼近已知函数所需项数:k
% 逼近点的x坐标:x0
% 求得的勒让德逼近多项式或在x0处的逼近值f
syms t;
P(1:k+1) = t;
P(1) = 1;
P(2) = t;
c(1:k+1) = 0.0;
c(1)=int(subs(y,findsym(sym(y)),sym('t'))*P(1),t,-1,1)/2;
c(2)=int(subs(y,findsym(sym(y)),sym('t'))*P(2),t,-1,1)/2;
f = c(1)+c(2)*t;
for i=3:k+1
P(i) = ((2*i-3)*P(i-1)*t-(i-2)*P(i-2))/(i-1);
c(i) = int(subs(y,findsym(sym(y)),t)*P(i),t,-1,1)/2;
f = f + c(i)*P(i);
if(i==k+1)
if(nargin == 3)
f = subs(f,'t',x0);
else
f = vpa(f,6);
end
end
end
调用:syms x t;
f=x^4+2*x^3;
f = Legendre(f,3);
fourier(f,t)
clc
alpha=5.2182;
n=1.55;
e=0;
f=0;
for l=1:50
syms x f1 f2
if l==1
f1=sin(x)./x-cos(x);
f1dot=diff(f1,x,l);
f2=(sin(x)+i*cos(x))./x-cos(x)+i*sin(x);
f2dot=...
全部展开
clc
alpha=5.2182;
n=1.55;
e=0;
f=0;
for l=1:50
syms x f1 f2
if l==1
f1=sin(x)./x-cos(x);
f1dot=diff(f1,x,l);
f2=(sin(x)+i*cos(x))./x-cos(x)+i*sin(x);
f2dot=diff(f2,x,l);
else
f1=(pi*x/2).*besselj(l+0.5,x);
f1dot=(pi*x/2).*besselj(l-0.5,x)-l*(pi*x/2).*besselj(l+0.5,x)./x;
f2=(pi*x/2).*(besselj(l+0.5,x)-i*bessely(l+0.5,x));
f2dot=(pi*x/2).*(besselj(l-0.5,x)-i*bessely(l-0.5,x))-l*(pi*x/2).*(besselj(l+0.5,x)-i*bessely(l+0.5,x))./x;
end
g1=inline(vectorize(f1), x);
g1dot=inline(vectorize(f1dot), x);
g2=inline(vectorize(f2), x);
g2dot=inline(vectorize(f2dot), x);
a1=(g1dot(n*alpha).*g1(alpha)-n*g1(n*alpha).*g1dot(alpha))./(g1dot(n*alpha).*g2(alpha)-n*g1(n*alpha).*g2dot(alpha));
b1=(n*g1dot(n*alpha).*g1(alpha)-g1(n*alpha).*g1dot(alpha))./(n*g1dot(n*alpha).*g2(alpha)-g1(n*alpha).*g2dot(alpha));
e=e+(2*l+1)*(abs(a1).^2+abs(b1).^2);
f=f+(2*l+1)*real(a1+b1);
end
kext=2/alpha.^2.*f
ksca=2/alpha.^2.*e
收起