Conversion to function_handle from double is not possible.
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
tutkuçiçek duruer
le 11 Juin 2020
0 votes
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
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!