Hello,
I'm fairly new to matlab so I'm not too familiar with the way all of the functions work. I need to plot a function I have been given :
but I am having trouble defining it. I've tried the following:
syms k x
f = matlabFunction(b0 + symsum(a(k)*sin(k*x) + b(k)*cos(k*x)));
This gives me an error stating "Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression."
Can someone help me out? :)

댓글 수: 1

Sahil
Sahil 2022년 9월 18일
syms k x f = matlabFunction(b0 + symsum(a(k)*sin(k*x) + b(k)*cos(k*x)));

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2019년 5월 30일
편집: Matt J 2019년 5월 30일

1 개 추천

An efficient implementation would be,
a=___;
b=___;
b0=___;
fplot(@(z) myFourier(z,a,b,b0));
function f=myFourier(x,a,b,b0)
n=numel(a);
arg=x(:).*(1:n);
f=b0+sin(arg)*a(:)+cos(arg)*b(:);
f=reshape(f,size(x));
end

댓글 수: 3

Rozalia Korycka
Rozalia Korycka 2019년 5월 30일
편집: Rozalia Korycka 2019년 5월 30일
Thanks a lot! It gives me a bunch of warnings but it does plot it so that's fine for my needs. I guess I wasn't even close... :)
Matt J
Matt J 2019년 5월 30일
I'm baffled by the warnings. The function is vectorized as fplot requires.
That's exactly the opposite of what the warning says hahah but I don't know since I don't even know what is that supposed to mean

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

질문:

2019년 5월 30일

댓글:

2022년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by