First of all, I want to thank you for asking this question; I am a basic user of LaTeX and by thinking about your question, I learned so many things. Here is the code and my solution to your problem;

% pdflatex
\documentclass{standalone}
\usepackage{siunitx}
\sisetup{round-mode=places,round-precision=1}
%
\usepackage{tikz}
\usepackage{pgfplots}
%
\def\colora{red}
\def\colorb{green}
\begin{document}
\begin{tikzpicture}
\pgfmathdeclarefunction{q}{2}{\pgfmathparse{(4.9/(#1^2))*(cosh(#1*#2)-cos(#1*#2)}}
\begin{axis}
[
axis lines = center,
grid=both,minor tick num=1,
xlabel=$t$,ylabel=$q$,
tick align=inside,
every axis y label/.style={rotate=0, black, at={(0.5,1.05)},},
every axis x label/.style={rotate=0, black, at={(1.05,0)},},
%
legend style={at={(0.65,1.0)},
anchor=north west,legend columns=1},
%
domain=-5:5,
smooth,
]
\foreach \w in {0.10,0.20,...,0.5} {
\pgfmathparse{200*\w}
\xdef\x{\pgfmathresult}
%
\edef\tempa{\noexpand\addlegendentry{\num{\w}}}\tempa
\edef\tempb{\noexpand\addplot [\colora!\x!\colorb]}\tempb{q(\w,x)};
}
\end{axis}
\end{tikzpicture}
\end{document}
I have defined the function at the line
\pgfmathdeclarefunction{q}{2}{\pgfmathparse{(4.9/(#1^2))*(cosh(#1*#2)-cos(#1*#2)}}
however, one may not define his function as above and simply type it in front of the \addplot
syntax in his code. There is no difference here. The point I want to mention is that you introduced part of your function as cos(w*t)
. Please make sure how the variable should be in your function. Should it be in degree or radian? By checking the values of the plot as output of your MWE in your question; I can see that you did not use the degree function. But, if you have to introduce the variables in degree, please change that part to cos(deg(#1*#2))
. Your plots change slightly.
Using iteration syntaxes to decrease the amount of codes:
For the easiness of drawing many plots without hesitation to have long similar codes, I tried using the iterative syntax \foreach
. This part consists of a part to produce the legend, one part to draw plots and one part which focuses on the colour of the plots. In the line
\foreach \w in {0.10,0.20,...,0.5} {
you may introduce the values you need for the w
as in your function. I chose the values to be 0.1, 0.2, 0.3, 0.4
and 0.5
but you can choose whatever your like. Just introduce the lowerbound, step and upperbound of your iteration. As you can see, there are problems using \addlegendentry in a loop with pgfplots. I tried a temporary technique to solve this part but if you check the alternative codes in this answer, you can see that there is no need to such temp technique for at least the legends.
Varied colouring for the set of plots:
For the purpose of varying the colour of the plots, I used the solution which is described in this answer. If you don't go through that way, pgfplots will choose nice colours for your plots too; just replace the following syntaxes and see the results.
\edef\tempb{\noexpand\addplot +[mark=none]}\tempb{q(\w,x)};

Problems with legends and plotting syntaxes inside an iteration:
As you wanted to plot iteratively, you should bring the legends and the plotting parts inside an iteration syntax. This causes many problems which we should think about, parts of which is described in the previous part. I will point to this problem alongside with other problem which I faced for floats and answer all these together.
There were some problems with number floating as part of the legend; if one does not pay attention to it, the legend's output would be so ugly.

The reason for such problem is described in an answer to this problem. However, the solution for the plot in your question was different. There were many different solutions to face this problem. I chose to use the sinitx
package because it was easier for me to work with as a basic user. It is partially discussed in this question and answer.
@JosephWright proposed in the chatroom that
You need to use a printing function on \w rather than just inserting
\w, for example; (link)
\foreach \w in {0.1,0.2,...,1} {
\pgfmathparse{100*\w}
\edef\x{\pgfmathresult}
\edef\temp{\noexpand\addplot [\colora!\x!\colorb]}\temp{q(\w,x)};
\edef\temp{\noexpand\addlegendentry{\noexpand\pgfmathprintnumber{\w}}}\temp
}
Or you could force \w to take the 'right' values, of course I'd
probably force 1 to 1.0 and tidy up a little more (link)
\foreach \w in {0.1,0.2,...,1} {
\pgfmathparse{round(\w)}
\pgfmathparse{100*\w}
\edef\x{\pgfmathresult}
\edef\temp{\noexpand\addplot [\colora!\x!\colorb]}\temp{q(\w,x)};
\pgfkeys{/pgf/number format/.cd, fixed, precision = 1, zerofill}
\pgfmathprintnumberto{\w}{\temp}
\addlegendentryexpanded{\temp}
}
He also presented some other ways like (link) and (link) to plot the functions:
% pdflatex
\documentclass{standalone}
\usepackage{expl3}
\usepackage{pgfplots}
\ExplSyntaxOn
\cs_new_eq:NN \fpeval \fp_eval:n
\ExplSyntaxOff
\begin{document}
\begin{tikzpicture}
\pgfmathdeclarefunction{q}{2}{\pgfmathparse{(4.9/(#1^2))*(cosh(#1*#2)-cos(#1*#2)}}
\begin{axis}
\foreach \w in {10,20,...,100} {
\edef\temp{\noexpand\addplot [red!\w]}\temp{q((\w/100),x)};
\addlegendentryexpanded{\fpeval{\w/100}}
}
\end{axis}
\end{tikzpicture}
\end{document}

As you can see, all of these two solutions are presented by the expl3 package and LaTeX3 programming.
% pdflatex
\documentclass{standalone}
\usepackage{expl3}
\usepackage{pgfplots}
\ExplSyntaxOn
\cs_new_eq:NN \fpeval \fp_eval:n
\ExplSyntaxOff
\begin{document}
\begin{tikzpicture}
\pgfmathdeclarefunction{q}{2}{\pgfmathparse{(4.9/(#1^2))*(cosh(#1*#2)-cos(#1*#2)}}
\begin{axis}
\foreach \w in {0.1,0.2,...,1.0} {
\edef\temp{\noexpand\addplot [red!\fpeval{100 * \w}]}\temp{q(\w,x)};
\addlegendentryexpanded{\fpeval{round(\w,1)}}
}
\end{axis}
\end{tikzpicture}
\end{document}
If we want to bring the legends and addplot
syntaxes, we face lots of problems. It's up to you to choose which way to handle the floats, iterations and legend problems. If you have access to the required package then follow my solution. If not, go through the other solutions.