Alternating forward and reversed cos function

1 visualizzazione (ultimi 30 giorni)
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 Commento
Torsten
Torsten il 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 ?

Accedi per commentare.

Risposta accettata

John D'Errico
John D'Errico il 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.

Più risposte (1)

Xymbu
Xymbu il 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!

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by