Why I'm I getting this error when I try to call the function myfourier in another m file?
Show older comments
myfourier.m file
function [a0 an bn fs] = myfourier(f, flim, N)
syms t
syms N
T = flim(end)-flim(1);
w0 = 2*pi/T;
fs = 0.0;
for i = 0:N
for k= 2:length(flim)
an= (2/T)*int(f(k-1)*cos(i*w0*t),t,flim(k-1),flim(k));
ann(i+1)=an;
bn= (2/T)*int(f(k-1)*sin(i*w0*t),t,flim(k-1),flim(k));
bnn(i+1)=bn;
fs= fs + an*cos(w0*i*t)+bn*sin(w0*i*t);
end
if i==0
fs = fs/2;
end
%a0 is calculated first (for i=0). The Fourier series starts with a0/2 ...
end
a0 = 0.0;
for k= 2:length(flim)
a0= a0+(2/T)*int(f(k-1),t,flim(k-1),flim(k));
end
disp('a0=')
disp(a0)
for i= 1:N
disp('an=')
disp(ann(i+1))
end
for i= 1:N
disp('bn=')
disp(bnn(i+1))
end
fs
title("Fourier series approximation of f against estimated function f with N="+N)
hold on
fourier = matlabFunction(fs);
grid on
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
xlabel('x')
ylabel('y')
t = flim(1):0.01:flim(end);
plot(t,fourier(t))
for k= 2:length(flim)
fplot(f(k-1),[flim(k-1), flim(k)])
end
legend('Fourier approximation of f')
end
Excercise4.m file
f= [-t- 2*pi, -t, 2*pi- t, -t-4*pi];
flim= [-3*pi,-pi,pi,3*pi,5*pi];
N= 5;
[a0 an bn fs] = myfourier(f, flim, N);
Error using symengine>@(t)(sin(t.*pi).*4.0)./pi+(sin(t.*pi.*3.0).*(4.0./3.0))./pi+(sin(t.*pi.*5.0).*(4.0./5.0))./pi+6.0
Too many input arguments.
Error in Excercise4 (line 5)
[a0 an bn fs] = myfourier(f, flim, N);
1 Comment
Rena Berman
on 27 Dec 2022
(Answers Dev) Restored edit
Accepted Answer
More Answers (0)
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
