create matrix with integral

3 visualizaciones (últimos 30 días)
Mohammed Hachemi
Mohammed Hachemi el 15 de Sept. de 2019
Respondida: Mohammed Hachemi el 15 de Sept. de 2019
Hello
I need your help , I am beginner in matlab and want to use matlab to calculate integral and create matrix with variable n and m.
x = [-1,1]
∫ (f(x,n)*f(x,m)dx
I want to creat matrix
f(x,1)*(f(x,1) f(x,1)*(f(x,2) .....
f(x,2)*(f(x,1) f(x,1)*(f(x,1)
.
.
I try this code but I need your help to create one
P = 5; exemple
fun(1) =@(x)(1-x)/2;
fun(2) =@(x)(1+x)/2;
fun(n) =@(x) sin(pi/2*(n-1).*(1+x)); if n >= 2;
for m = 1:P;
for n = 1:P;
L[n,m]=integral((fun(m).*fun(n)),-1,1,-1,1);
end
end

Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de Sept. de 2019
P = 5;
for m = 1:P;
for n = 1:P;
L(n,m) = integral( @(x) fun(x,n).*fun(x,n)), -1, 1);
end
end
function y = fun(x, n)
%warning: x will be a vector or array!
if n == 1
y = (1-x)/2;
elseif n == 2
y = (1+x)/2;
else
y = sin(pi/2*(n-1).*(1+x));
end

Más respuestas (1)

Mohammed Hachemi
Mohammed Hachemi el 15 de Sept. de 2019
Thank you for your answer but it doesn't work.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by