Alternating forward and reversed cos function

조회 수: 2 (최근 30일)
Xymbu
Xymbu 2022년 3월 15일
답변: Xymbu 2022년 3월 15일
I have a function that im not really sure how to get a matlab function for. I have several cycles of a cosine function, then those cycles are reversed and that pattern is repeated indefinitley. It's like a rastor scan over time. I am trying to find a way to come up with an equation for this so that I dont have to store all the data in a matrix ahead of time because the matrix becomes huge and takes up too much memory. Anyone have any ideas?
  댓글 수: 1
Torsten
Torsten 2022년 3월 15일
I have several cycles of a cosine function, then those cycles are reversed and that pattern is repeated indefinitley.
This means what mathematically ? For what are you trying to find an equation ?

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

채택된 답변

John D'Errico
John D'Errico 2022년 3월 15일
This may be easier than you think. But since you asked, and had no idea how to do it, it may be harder than you think. DRAT. Now I'm so confused.
The trick is to start by generating a version of a sawtooth function, but a specific kind thereof.
sawtooth = @(t,period) abs(mod(t+period,2*period) - period);
period = 2*pi;
fplot(@(t) sawtooth(t,period),[0,50])
So now your forward and reverse cosine function will be simple. For example, suppose you have a function that is a normal cosine function on the interval [0,5]. but then it reverses direction.
Easy peasy now!
compositecos = @(t) cos(sawtooth(t,5));
fplot(compositecos,[0,50])
The nice thing is, the sawtooth function I wrote above will work when composed with any function you want.
As I said, easier than you may think. As long as you think a bit outside of the box.

추가 답변 (1개)

Xymbu
Xymbu 2022년 3월 15일
This is what I was looking for. What I am actually applying this to is a little bit more complex than how I poorly explained it. It has a few more dimensions but I had never done this method but I was able to apply this and it works well so thanks!

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by