How to substitute into general solution of ODE coefficients from Solve?

I am trying to solve a differential equation. After solving it, I look for the coefficients according to some boundary conditions that give a certain system of algebraic equations. How can I place back into the general solution the roots of the algebraic system?

k = DSolve[{y'''[z] == -I*Betta*y'[z] + B}, y[z], z];
roots = Solve[
0 == c1 + c2*Cosh[I/2*(I*Betta)^0.5] +
c3/I*Sinh[I/2*(I*Betta)^0.5] + B/(2*I*Betta) &&
0 == c1 + c2*Cosh[I/2*(I*Betta)^0.5] -
c3/I*Sinh[I/2*(I*Betta)^0.5] - B/(2*I*Betta) &&
1 == c2*I*(I*Betta)^0.5*Sinh[I/2*(I*Betta)^0.5] +
c3*(I*Betta)^0.5*Cosh[I/2*(I*Betta)^0.5] + B/(I*Betta) &&
1 == -c2*I*(I*Betta)^0.5*Sinh[I/2*(I*Betta)^0.5] +
c3*(I*Betta)^0.5*Cosh[I/2*(I*Betta)^0.5] + B/(I*Betta), {c1, c2,
c3, B}];
k2 = k /. {C -> roots[[1, 1]], C -> roots[[1, 2]],
C -> roots[[1, 3]], B -> roots[[1, 4]]}

At the end I would like to have a function which I can plot with standard methods

• Why not directly express your equations in terms of the C[k]? Solve[0 == C +C Cosh[I/2*(I*Betta)^0.5] + ... && (* equations *), {C, C, C, B}] Mar 30 '17 at 9:55
• @J.M. The equations (equations) are the ones that you also wrote in Solve[0==C+C .... Maybe I wasn't clear, but I think your idea doesnt make sense. The first part of your Solve would be one of the equations that give the solution. The system of equations that give c1,c2,c3,B is exactly the one inside my Solve expressione. I want to substitute these solutions (which are given in vectorial form) INSIDE the function k(z) which comes from the DSolve and has got C,C,C,B.. inside, which I dont know how to replace with my c1,c2,c3,B. Mar 30 '17 at 10:11
• The idea is that you don't need the extra effort to transfer, say, c1, into C, since you can do DSolve[(* stuff *)] /. Solve[(* stuff *)]. That's why I'm saying that you can use C, etc. instead of c1, etc. in Solve[]. Mar 30 '17 at 10:19
• @J.M. Is there also a way to show each sine or cosine functions into sinh and cosh including imaginary unit. So far, I havent found much on documentation, rather the opposite. Mar 30 '17 at 10:45
• @AndreaG What are the four conditions?
– zhk
Mar 30 '17 at 15:40

k = DSolve[{y'''[z] == -I*Betta*y'[z] + B}, y[z], z];
gsol[z_] = y[z] /. Flatten[k];
gdsol[z_] = D[y[z] /. Flatten[k], z];
findCs = Solve[{gsol[-1/2] == 0, gsol[1/2] == 0, gdsol[-1/2] == 1,
gdsol[1/2] == 1}, {C, C, C, B}];
psol[z_, Betta_] = gsol[z] /. Flatten[findCs];
Plot[{Re[psol[z, 1]], Im[psol[z, 1]]}, {z, -1/2, 1/2}, PlotRange -> All, Frame -> True] • Thanks @MMM this is exactly what I was looking for! Apr 21 '17 at 15:15
• @AndreaG I am pleased that it helped.
– zhk
Apr 21 '17 at 15:22