Info
此问题已关闭。 请重新打开它进行编辑或回答。
Hey need assistance with fourier analysis questions
1 次查看(过去 30 天)
显示 更早的评论
function [x,f]=my_Fourier_series_generator(T,a0,an,bn,xrange,max_N)
x=linspace(xrange(1),xrange(2),1000);
% frequency wn
w=2*pi/T;
% initializing f at a0
f=a0;
syms n;
% Fourier series implementation
for n=1:max_N
aa=eval(an);
bb=eval(bn);
f=f+aa*cos(w*n*x)+bb*sin(w*n*x);
end
plot(x,f)
this is the code im trying to run
solution(1, 1/2, (2/(n*pi))*sin((n*pi)/2), 0, 0:10:200, 300)
this is the error I keep receiving
Error using eval
Must be a string scalar or character vector.
Error in solution (line 17)
bb=eval(bn);
0 个评论
回答(1 个)
Walter Roberson
2018-4-14
You are passing (2/(n*pi))*sin((n*pi)/2) in the position you call an . You ask to eval(an), so you are asking to eval((2/(n*pi))*sin((n*pi)/2)) . However, eval() can only work on string objects or character vectors.
The likelihood that you are using eval() appropriately is... rather low. You should probably be passing in function handles and evaluating the function handles. Like
aa = an(n)
after you have passed in
@(n) (2/(n*pi))*sin((n*pi)/2)
in that position.
2 个评论
Walter Roberson
2018-4-14
I said,
"after you have passed in @(n) (2/(n*pi))*sin((n*pi)/2) in that position".
You have not passed a function handle in that position: you have passed a scalar or vector of values.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!