Alternating forward and reversed cos function

1 view (last 30 days)
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 Comment
Torsten
Torsten on 15 Mar 2022
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 ?

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 15 Mar 2022
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.

More Answers (1)

Xymbu
Xymbu on 15 Mar 2022
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!

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!