0
$\begingroup$

Hi i how do i replace constant for k in this summation.

For following:

  1. Even 2*n Even replace k by a
  2. Even 2*n+1 Odd replace k by b

    enter image description here

Here is the code

ue[x_, t_, k_, n_] := 
           (1/2)*Sum[Subscript[k, j]*(Subscript[x, j - 1][t] - Subscript[x, j][t])^2,{j, 1, n + 1}]; 
$\endgroup$
2
$\begingroup$
Subscript[k, j_?EvenQ] = a;
Subscript[k, j_?OddQ] = b;

For extra conditions at $j=0$ and $j=n+1$ you can use a two-index form $k_{n,j}$:

Subscript[k, n_, 0] = 0;
Subscript[k, n_, j_] /; j == n + 1 = 0;
Subscript[k, n_, j_?EvenQ] = a;
Subscript[k, n_, j_?OddQ] = b;

Check:

With[{n = 10}, Table[Subscript[k, n, j], {j, 0, n + 1}]]

{0, b, a, b, a, b, a, b, a, b, a, 0}

$\endgroup$
  • $\begingroup$ sir how do i impose extra condition beside that above that k=0 at j=0 and j=n+1; k[0] = 0; k[n + 1] = 0; $\endgroup$ – Alrubaie Mar 12 at 18:14
  • $\begingroup$ ok i got it sir. thanks $\endgroup$ – Alrubaie Mar 12 at 18:20
  • $\begingroup$ Subscript[k, j_?EvenQ] = a; Subscript[k, j_?OddQ] = b; "to impose extra condition on beside that above that k=0 at j=0 and j=n+1; use " for n=4; Subscript[k, 0] = 0; Subscript[k, 4] = 0; $\endgroup$ – Alrubaie Mar 12 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.