How to obtain and work with steady-state part of DE solution? - maple

I'm trying to obtain resonance curves of the system. System can be described as
F,m,k:=2,1,4:
lambda:= beta/(2*m):
omega:=sqrt(k/m):
de:=diff(x(t),t$2)+2*lambda*diff(x(t),t)+omega^2*x(t)=F*cos(gamma1*t):
cond:=x(0)=0, D(x)(0)=0:
sol := dsolve({cond, de});
Solving gives sum of terms, some of which "die out" with time (since these terms have exp(-...*t)) and some of which form steady-state solution (solution for t -> ∞). This solution will be in form xstst=f(gamma1)*sin(...). In order to obtain resonance curves, I need to plot f(gamma1) (for chosen constant betas, say, 2,1,0.5,0.25,etc.).
I've solved this "by hand" and found f := F/(sqrt((-gamma1^2+omega^2)^2+4*lambda^2*gamma1^2)). Plotting this for any chosen beta gives the result needed, for example, for beta:=0.5 the plot is
I wonder if I can obtain these curves using maple functions only (without solving anything "by hand" at all).
[edited]

It does not make sense to expect Maple to represent the result in terms of either sin(theta) or cos(theta), using some formulas for those terms that appear nowhere in the problem specification and are entirely introduced by you.
The following is obtained using a radical (square root) in each of cond1 and cond2.
restart;
de := diff(x(t),t,t)+2*lambda*diff(x(t),t)+omega^2*x(t)=F*cos(gamma1*t):
cond := x(0)=0, D(x)(0)=0:
sol := dsolve({cond, de}):
E,T := selectremove(hastype,rhs(sol),specfunc(anything,exp)):
lprint(T);
F*(2*sin(gamma1*t)*gamma1*lambda-cos(gamma1*t)*gamma1^2
+cos(gamma1*t)*omega^2)/(gamma1^4+4*gamma1^2*lambda^2-
2*gamma1^2*omega^2+omega^4)
cond1 := cos(theta) = (-gamma1^2+omega^2)
/((-gamma1^2+omega^2)^2+4*lambda^2*gamma1^2)^(1/2):
cond2 := sin(theta) = (-2*lambda*gamma1)
/((-gamma1^2+omega^2)^2+4*lambda^2*gamma1^2)^(1/2):
frontend(algsubs, [numer(rhs(cond1))=lhs(cond1)*denom(rhs(cond1)),
numer(T)],
[{`+`,`*`,`=`},{}]):
frontend(algsubs, [numer(rhs(cond2))=lhs(cond2)*denom(rhs(cond2)),
%],
[{`+`,`*`,`=`},{}]):
ans := collect(combine(%, trig),cos)/denom(T):
lprint(ans);
F*cos(gamma1*t+theta)/(gamma1^4+4*gamma1^2*lambda^2-
2*gamma1^2*omega^2+omega^4)^(1/2)
subsans := eval(eval(ans,[lambda=beta/(2*m),omega=sqrt(k/m)]),
[F=2,m=1,k=4]):
lprint(subsans);
2*cos(gamma1*t+theta)
/(beta^2*gamma1^2+gamma1^4-8*gamma1^2+16)^(1/2)

I'm not sure I fully understand your question, but when I run your code I get some terms with exponentials, some with sines and some with cosines. You can grab the coefficient of the sine terms with
coeff( collect( rhs( sol ) , sin( gamma1 * t ) ) , sin( gamma1 * t ) , 1 )

Related

hyperpolic function integration in maple

Im trying to evaluate this function in maple
but I keep getting this answer, why isn't maple integrating properly. I tried numerically integrating it and it works but I need the analytical solution too.
restart;
sig := x->(exp((x-t)/a)-exp((-x-t)/a))
/(exp((x-t)/a)+exp((-x-t)/a)):
new := convert(simplify(convert(expand(sig(x)),trigh)),tanh);
new := tanh(x/a)
simplify(expand(convert(sig(x) - new, exp)));
0
Now, you originally wrote int(f*sig(x)/x,x).
You didn't indicate that f was a function of x, and as a mere constant it's not really important and could simply be pulled out in front of the integral as a constant factor. If f is some function of x then you really need to state what it is!
Let's consider int(sig(x)/x,x=c..d). Using the simplification new, that is just,
Q := Int( new/x, x=c..d );
Q := Int(tanh(x/a)/x, x = c .. d)
QQ := IntegrationTools:-Change(Q, y=x/a, y);
QQ := Int(tanh(y)/y, y = c/a .. d/a)
You said that you wanted an "analytical solution" by which I take it you mean an explicit formula for the symbolic integration result. But what do you want if the integral does not (mathematically) have a closed form exact, symbolic result?
Would you be content with an (exact, symbolic) series approximation?
H := (a,ord,c,d)
-> int(convert(series(eval(new/x,:-a=a),x,ord),
polynom),x=c..d):
# order 5
H(a, 5, c, d);
3 3 / 5 5\
d - c -c + d 2 \-c + d /
----- - -------- + ------------
a 3 5
9 a 75 a
For a specific example, taking a=2 and an (exact) series approximation of order 25, then the integral from x=0 to x=1 gets evaluated as an exact rational.
evalf(H(2, 25, 0, 1));
0.4868885956
Here's the numeric integration for those same values,
evalf(Int( eval(new/x,a=2), x=0..1 ));
0.4868885956
Specialized numeric quadrature could be as good as a series approximation for a variety of applications, but of course that would depend on what you intend on doing with the result.
This raises the question: what do you hope to do with some supposed "analytical result" that you cannot do with a black-box function that generates the floating-point numeric approximation? Why do you "need" an "analytic result"?
BTW, another way to simplify it (in case the construction above of new does not succeed in your Maple version):
new := convert(simplify(expand( numer(sig(x))/exp(-t/a) ))
/simplify(expand( denom(sig(x))/exp(-t/a) )),
compose,trigh,tanh);
/x\
new := tanh|-|
\a/

Integration of a system of differential equations MATLAB

I am a fairly new Matlab user which I had to explore to numerically integrate a system of differential equations. Now I am trying to resolve a simple equation but which gives me a "lambertw" output.
(s - 1) * exp(-s) = k
Therefore, for a given k, with k < exp(2) I should get approximately two different values of "s". Here is the bit of code I use for this task (using symbolic toolbox):
%%Hopf bifurcation calculations
syms s
solve((s-1) * exp(-s) == k, s)
%uhopf = s*k
And the output:
1 - lambertw(0, -(3*exp(1))/25)
After looking at some examples I tried to get an explicit solution with no success:
syms x
x=solve('(s-1)*exp(-s) == k')
Finally, my question is how do I change the result given in the first place into a simple numerical value that fir a given k would give me s1 and s2. Any hint or help would be much appreciated ! I am still looking at some other examples.
If I understand your question correctly, you can use the eval() function to evaluate the string to retrieve a simple numerical example.
e.g.
char s;
char k;
A=solve('(s-1) * exp(-s) = k', 'k=exp(1)');
sol_s=A.s(1);
sol_k=A.k(1);
ans=eval(sol_s)

Cross characteristics of a non-linear equation in Matlab

I'd like to create a Matlab plot of propeller angular velocity in terms of applied current. The point is, this requires combining two interdependent sets of data.
Firstly, drag coefficient c_d depends on angular velocity omega (I have no formula, just data) as seen on the plot below - the characteristics c_d(omega) could be easily linearised as c_d(omega) = p*omega + p_0.
Secondly, omega depends not only on applied current i, but also on the drag coefficient c_d(omega).
A script that solves the case, where c_d is constant below. It must be somehow possible to join those two using Matlab commands. Thanks for any help.
%%Lookup table for drag coefficient c_d
c_d_lookup = [248.9188579 0.036688351; %[\omega c_d]
280.2300647 0.037199094;
308.6091183 0.037199094;
338.6636881 0.03779496;
365.8908244 0.038305703;
393.9557188 0.039156941;
421.9158934 0.039667683;
452.2846224 0.040348674;
480.663676 0.041199911;
511.032405 0.042051149;
538.9925796 0.042561892;
567.2669135 0.043242882;
598.4734005 0.043668501;
624.1297405 0.044264368;
651.9851954 0.044604863;
683.6105614 0.045200729];
subplot(2,1,1)
plot(c_d_lookup(:,1), c_d_lookup(:,2))
title('This is how c_d depends on \omega')
ylabel('c_d')
xlabel('\omega [rad/s]')
%%Calculate propeller angular speed in terms of applied current. omega
%%depends on c_d, which in turn depends on omega. The formula is:
% omega(i) = sqrt(a*i / (b * c_d(omega)))
% Where:
% i - applied current
% omega - propeller angular velocity
% a,b - coefficients
i = [1:15];
a = 0.0718;
b = 3.8589e-005;
%If c_d was constant, I'd do:
omega_i = sqrt(a .* i / (b * 0.042));
subplot(2,1,2)
plot(i, omega_i)
ylabel({'Propeller ang. vel.', '\omega [rad/s]'})
xlabel('Applied current i[A]')
title('Propeller angular velocity in terms of applied current')
EDIT:
Trying to follow bdecaf's solution. So I created a function c_d_find, like so:
function c_d = c_d_find(omega, c_d_lookup)
c_d = interp1(c_d_lookup(:,1), c_d_lookup(:,2), omega, 'linear', 'extrap');
end
I don't know anything about Matlab function handles, but seem to understand the idea... In Matlab command window I typed:
f = #(omega) omega - sqrt(a .* i / (b * c_d_find(omega, c_d_lookup)))
which I hope created the correct function handle. What do I do next? Executing the below doesn't work:
>> omega_consistent = fzero(f,0)
??? Operands to the || and && operators must be convertible to logical scalar
values.
Error in ==> fzero at 333
elseif ~isfinite(fx) || ~isreal(fx)
hmmm...
Wonder if I understand correctly - but looks like you are looking for a consistent solution.
Your equations don't look to complicated I would outline the solution like this:
Write a function function c_d = c_d_find(omega) that does some interpolation or so
make a function handle like f = #(omega) omega - sqrt(a .* i / (b * c_d_find(omega))) - this is zero for consistent omega
calculate a consistent omega with omega_consistent =fzero(f,omega_0)

How to calculate the convolution of a function with itself in MATLAB and WolframAlpha?

I am trying to calculate the convolution of
x(t) = 1, -1<=t<=1
x(t) = 0, outside
with itself using the definition.
http://en.wikipedia.org/wiki/Convolution
I know how to do using the Matlab function conv, but I want to use the integral definition. My knowledge of Matlab and WolframAlpha is very limited.
I am still learning Mathematica myself, but here is what I came up with..
First we define the piecewise function (I am using the example from the Wikipedia page)
f[x_] := Piecewise[{{1, -0.5 <= x <= 0.5}}, 0]
Lets plot the function:
Plot[f[x], {x, -2, 2}, PlotStyle -> Thick, Exclusions -> None]
Then we write the function that defines the convolution of f with itself:
g[t_] = Integrate[f[x]*f[t - x], {x, -Infinity, Infinity}]
and the plot:
Plot[g[t], {t, -2, 2}, PlotStyle -> Thick]
EDIT
I tried to do the same in MATLAB/MuPad, I wasn't as successful:
f := x -> piecewise([x < -0.5 or x > 0.5, 0], [x >= -0.5 and x <= 0.5, 1])
plot(f, x = -2..2)
However when I try to compute the integral, it took almost a minute to return this:
g := t -> int(f(x)*f(t-x), x = -infinity..infinity)
the plot (also took too long)
plot(g, t = -2..2)
Note the same could have been done from inside MATLAB with the syntax:
evalin(symengine,'<MUPAD EXPRESSIONS HERE>')
Mathematica actually has a convolve function. The documentation on it has a number of different examples:
http://reference.wolfram.com/mathematica/ref/Convolve.html?q=Convolve&lang=en
I don't know much about Mathematica so I can only help you (partially) about the Matlab part.
To do the convolution with the Matlab conv functions means you do it numerically. What you mean with the integral definition is that you want to do it symbolically. For this you need the Matlab Symbolic Toolbox. This is essentially a Maple plugin for Matlab. So what you want to know is how it works in Maple.
You might find this link useful (wikibooks) for an introduction on the MuPad in Matlab.
I tried to implement your box function as a function in Matlab as
t = sym('t')
f = (t > -1) + (t < 1) - 1
However this does not work when t is ob symbolic type Function 'gt' is not implemented for MuPAD symbolic objects.
You could declare f it as a piecewise function see (matlab online help), this did not work in my Matlab though. The examples are all Maple syntax, so they would work in Maple straight away.
To circumvent this, I used
t = sym('t')
s = sym('s')
f = #(t) heaviside(t + 1) - heaviside(t - 1)
Unfortunately this is not successful
I = int(f(s)*f(t-s),s, 0, t)
gives
Warning: Explicit integral could not be found.
and does not provide an explicit result. You can still evaluate this expression, e.g.
>> subs(I, t, 1.5)
ans =
1/2
But Matlab/MuPad failed to give you and explicit expression in terms of t. This is not really unexpected as the function f is discontinuous. This is not so easy for symbolic computations.
Now I would go and help the computer, fortunately for the example that you asked the answer is very easy. The convolution in your example is simply the int_0^t BoxFunction(s) * BoxFunction(t - s) ds. The integrant BoxFunction(s) * BoxFunction(t - s) is again a box function, just not one that goes from [-1,1] but to a smaller interval (that depends on t). Then you only need to integrate the function f(x)=1 over this smaller interval.
Some of those steps you would have to to by hand first, then you could try to re-enter them to Matlab. You don't even need a computer algebra program at all to get to the answer.
Maybe Matematica or Maple could actually solve this problem, remember that the MuPad shipped with Matlab is only a stripped down version of Maple. Maybe the above might still help you, it should give you the idea how things work together. Try to put in a nicer function for f, e.g. a polynomial and you should get it working.

assigning in system of differential equations

when i solve numerically a system of two differential equations:
s1:=diff(n[Di](t), t)=...;
s2:=diff(n[T](t), t)=...;
ics:={...}; #initial condition.
sys := {s1, s2, ics}:
sol:=dsolve(sys,numeric);
with respect to "t",then the solution (for example)for "t=4" is of the form, sol(4):
[t=4, n1(t)=const1, n2(t)=const2].
now, how is possible to use values of n1(t) and n2(t) for all "t"'s in another equation, namely "p", which involved n1(t) or n2(t)(like: {p=a+n1(t)*n2(t)+f(t)},where "a" and "f(t)" are defined), and to plot "p" for an interval of "t"?
Perhaps an example will help.
s1:=diff(n1(t), t)=sin(t);
s2:=diff(n2(t), t)=cos(t);
ics:={n1(0)=1,n2(0)=0}:
sys := {s1, s2} union ics:
sol:=dsolve(sys,numeric,output=listprocedure);
N1:=eval(n1(t),sol);
N2:=eval(n2(t),sol);
N1(0);
N1(1.1);
N2(0);
N2(1.1);
p := 11.3 + N1*N2 + tan:
plot(p, 0..1.1);
You might look at the DEplot routine, which is specialized for plotting ode solutions.