Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Warning: Explicit integral could not be found. Error

조회 수: 1 (최근 30일)
Carl
Carl 2011년 9월 12일
마감: MATLAB Answer Bot 2021년 8월 20일
This program is tasked with computing a partial trigonometric Fourier series from n=1 -> n = 25 and graphing the partial sums along with a given piecewise function to show that as the amount of partial sums increases so to does the accuracy of the graph of the trigonometric Fourier partial sums. I have resolved several issues with undefined and unfound functions but know I am getting the following error: {Warning: Explicit integral could not be found.}
Any assistance on solving this issue would be greatly appreciated.
SCRIPT
syms t k L n
addpath('C:\Documents and Settings\crs0013.COE\My Documents\MATLAB\FS\')
evalin(symengine,'assume(k,Type::Integer)');
a = @(f,t,k,L) int(f*cos(k*pi*t/L)/L,t,-L,L);
b = @(f,t,k,L) int(f*sin(k*pi*t/L)/L,t,-L,L);
fs = @(f,t,n,L) a(f,t,0,L)/2 + ...
symsum(a(f,t,k,L)*cos(k*pi*t/L) + b(f,t,k,L)*sin(k*pi*t/L),k,1,n);
f = fs;
pretty(fs(f,t,25,1))
ezplot(fs(f,t,25,1),-1,1)
hold on
ezplot(f,-1,1)
hold off
title('Partial sum with n=25')
FUNCTION
function [fs] = FourierSeries(t,k,L)
function x = piecewise(t)
x = zeros(size(t));
t1 = t < 0 | t >= 4;
x(t1) = t(t1) - 4;
t2 = 0 <= t & t < 2;
x(t2) = sin((pi*t(t2).^2)/4);
t3 = 2 <= t & t < 3;
tt3 = t(t3);
x(t3) = 5*tt3-tt3.^2-6;
t4 = 3 <= t & t < 4;
x(t4) = 0;
end
k = k(:);
t = t(:).';
fs = sum(bsxfun(@times,arrayfun(@(k)quad(@(t1)piecewise(t1).*...
cos(k*pi*t1/L)/L,-L,L),k),cos(k*pi*t/L)) +...
bsxfun(@times,arrayfun(@(k)quad(@(t1)piecewise(t1).*...
sin(k*pi*t1/L)/L,-L,L),k),sin(k*pi*t/L)));
end

답변 (1개)

Walter Roberson
Walter Roberson 2011년 9월 12일
You are attempting to take the integral of a function handle.
You have f = fs; where fs was defined as a function handle, and then you invoke fs(f,...) so you are passing the function handle as the first parameter to the same function handle. Your call to a() inside the definition of fs has f as its first parameter so a() is being passed the function handle as its first parameter. Your a() then involves int(f*cos(k*pi*t/L)/L,t,-L,L) which is attempting to integrate the function handle multiplied by something. I'm surprised it did not outright break, since it is illegal to multiply a function handle by anything. Perhaps it interpreted it as an implicit call to f with no parameters.. or perhaps it just recursed around until it realized that This Is Not Going To Work.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by