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$

1 Answer 1

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$
3
  • $\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
    Commented Mar 12, 2019 at 18:14
  • $\begingroup$ ok i got it sir. thanks $\endgroup$
    – Alrubaie
    Commented Mar 12, 2019 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
    Commented Mar 12, 2019 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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