Alternating forward and reversed cos function
2 views (last 30 days)
Show older comments
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
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 ?
Accepted Answer
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.
0 Comments
More Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!