Conversion to function_handle from double is not possible.
이전 댓글 표시
The error is "The following error occurred converting from function_handle to double:" and it has problem on line 20 of code that I attached. Does anyone can help to fix this code? please.
function [x,w]=gauss_legendre(n)
syms p%legendre polynomial vector
syms polmat % Jacobi matrix
syms y% independent variable
p=zeros(n,1);
polmat=zeros(n,n);
i=1;
while(i<=n) %generate Jacobi matrix
if(i<=(n-1))
polmat(i,i+1)=sqrt((i^2)/((4*(i^2)) -1));
end
if(1<i)
polmat(i,i-1)=sqrt(((i-1)^2)/((4*((i-1)^2)) -1));
end
i=i+1;
end
i=3;
p(1,1)=1/sqrt(2); %first Legendre polynomial
p(2,1)=@(y) sqrt(3/2)*y; %second Legendre polynomial
while(i<=n) %generate Legendre polynomial by induction
p(i,1)=@(y) (sqrt((4*(i-1)^2) -1)/(i-1)) *(y*p(i-1,1)-(i-2)*p(i-2,1)/sqrt((4*(i-2)^2) -1));
i=i+1;
end
x=eig(polmat); %get eigenvalues as vector form
i=1;
w=zeros(n,1); %initialize weights as vector form
while(i<=n)
y=x(i,1); %input value to y
w(i,1)=(norm(p(y)))^(-2);%This form is calculated at problem 3
i=i+1;
end
end
채택된 답변
추가 답변 (1개)
tutkuçiçek duruer
2020년 6월 11일
0 개 추천
x1=0.1
x2=0.5
x3=5
f(x1)=30.20
f(x2)=7
f(x3)=10.6
x4=x2-0.5*((((x2-x1)^2)*(f(x2)-f(x3)))-((x2-x3^2)*(f(x2)-f(x1)))/(((x2-x1))*(f(x2)-f(x3)))-((x2-x3)*(f(x2)-f(x1))))
Conversion to function_handle from double is not possible.
what can ı do
카테고리
도움말 센터 및 File Exchange에서 기호와 수치 간 변환에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!