I have a function ${\dot{\varphi } = \gamma - F(\varphi )}$ (where $F(\varphi)$ - is 2${\pi }$-periodic function) and graph of function $F(\varphi)$.
So I need to create a program that outputs 6 plots of φ(t) for different meaning of $\gamma (\gamma= 0.1, 0.5, 0.95, 1.05, 2, 5)$, and t ∈ [0, 100]
I've got a following F(φ) function: $$F(\phi)=\begin{cases} & {-\frac{\phi}{a}-\frac{\pi}{a}}, &\text{if } {\phi \in [-\pi, -\pi + a]},\\ & -1, &\text{if } {\phi \in [-\pi + a, - a]}, \\ & -\frac{\phi}{a}, &\text{if } {\phi \in [- a, a]}, \\ & 1, &\text{if } {\phi \in [a, \pi- a]},\\ & {-\frac{\phi}{a}+\frac{\pi}{a}},&\text{if } {\phi \in [\pi-a, \pi]}. \end{cases}$$
^
|
|1 ______
| /| \
| / | \
| / | \
__-π_______-a____|/___|________\π____>
\ | /|0 a
\ | / |
\ | / |
\ |/ |
¯¯¯¯¯¯ |-1
I've tried to do it in MATLAB but I faced with some problems. I don't know what to put in ode45 function (on which section should each part of the graph be displayed and what is the initial value to take). Because the evolution of $\phi(t)$ must be continuous. It's a code for $\gamma= 0.1$
hold on;
df1dt=@(t,f1) 0.1 - f1 - 3.14;
df2dt= @(t,f2)- 1;
df3dt=@(t,f3) 0.1 + f3;
df4dt= @(t,f4)+1;
df5dt=@(t,f5) 0.1- f5 + 3.14;
[T1,Y1] = ode45(df1dt, ...);
[T2,Y2] = ode45(df2dt, ...);
[T3,Y3] = ode45(df3dt, ...);
[T4,Y4] = ode45(df4dt, ...);
[T5,Y5] = ode45(df5dt, ...);
plot(T1,Y1);
plot(T2,Y2);
plot(T3,Y3);
plot(T4,Y4);
plot(T5,Y5);
hold off;
title('\gamma = 0.1')
As a first step, you have to implement the periodicity of $F$ by reducing the argument to a basic period. Your function has odd symmetry, so use $F(-x)=-F(x)$ to reduce the number of cases.
Then you can solve your ODE in just one call,
The full script that contains the main program and the functions as subroutines in one file can look like this:
There are some tricks that allow to leave out the enclosing function, but it is not very intuitive as the default behavior on loading the script is to call the first function in the script without arguments.