3
$\begingroup$
   R= {{(1/2 Cos[b z1] - 1/2 Cos[b z1] Cos[t]) Sin[b (L - z1)] + 
       Cosh[b (L - z1)] (-(1/2) Sin[b z1] - 1/2 Cos[t] Sin[b z1]) + 
       Cos[b (L - z1)] (1/2 Sin[b z1] - 
          1/2 Cos[t] Sin[b z1]) + (1/2 Cos[b z1] + 
          1/2 Cos[b z1] Cos[t]) Sinh[b (L - z1)], 
      Cos[b (L - z1)] (1/2 Cos[b z1] - 
          1/2 Cos[b z1] Cos[t]) + (-(1/2) Cos[b z1] - 
          1/2 Cos[b z1] Cos[t]) Cosh[b (L - z1)] + 
       Sin[b (L - z1)] (-(1/2) Sin[b z1] + 
          1/2 Cos[t] Sin[b z1]) + (-(1/2) Sin[b z1] - 
          1/2 Cos[t] Sin[b z1]) Sinh[
         b (L - z1)], (1/2 Cosh[b z1] + 1/2 Cos[t] Cosh[b z1]) Sin[
         b (L - z1)] + (1/2 Cosh[b z1] - 1/2 Cos[t/2]^2 Cosh[b z1] + 
          1/2 Cosh[b z1] Sin[t/2]^2) Sinh[b (L - z1)] + 
       Cos[b (L - z1)] (-(1/2) Sinh[b z1] - 1/2 Cos[t] Sinh[b z1]) + 
       Cosh[b (L - z1)] (1/2 Sinh[b z1] - 1/2 Cos[t] Sinh[b z1]), 
      Cos[b (L - z1)] (-(1/2) Cosh[b z1] - 1/2 Cos[t] Cosh[b z1]) + 
       Cosh[b (L - z1)] (1/2 Cosh[b z1] - 1/2 Cos[t] Cosh[b z1]) + 
       Sin[b (L - z1)] (1/2 Sinh[b z1] + 1/2 Cos[t] Sinh[b z1]) + 
       Sinh[b (L - z1)] (1/2 Sinh[b z1] - 1/2 Cos[t/2]^2 Sinh[b z1] + 
          1/2 Sin[t/2]^2 Sinh[b z1]), 
      1/2 Cos[b (L - z1)] Cos[a b^2 z1] Sin[t] + 
       1/2 Cos[a b^2 z1] Cosh[b (L - z1)] Sin[t] - (
       a A L^2 Sin[b (L - z1)] Sin[a b^2 z1] Sin[t])/(2 b Iyy) + (
       a A L^2 Sin[a b^2 z1] Sin[t] Sinh[b (L - z1)])/(2 b Iyy), (
       a A L^2 Cos[a b^2 z1] Sin[b (L - z1)] Sin[t])/(2 b Iyy) + 
       1/2 Cos[b (L - z1)] Sin[a b^2 z1] Sin[t] + 
       1/2 Cosh[b (L - z1)] Sin[a b^2 z1] Sin[t] - (
       a A L^2 Cos[a b^2 z1] Sin[t] Sinh[b (L - z1)])/(
       2 b Iyy)}, {-b^2 (1/2 Cos[b z1] - 1/2 Cos[b z1] Cos[t]) Sin[
         b (L - z1)] + 
       b^2 Cosh[b (L - z1)] (-(1/2) Sin[b z1] - 1/2 Cos[t] Sin[b z1]) - 
       b^2 Cos[b (L - z1)] (1/2 Sin[b z1] - 1/2 Cos[t] Sin[b z1]) + 
       b^2 (1/2 Cos[b z1] + 1/2 Cos[b z1] Cos[t]) Sinh[
         b (L - z1)], -b^2 Cos[
         b (L - z1)] (1/2 Cos[b z1] - 1/2 Cos[b z1] Cos[t]) + 
       b^2 (-(1/2) Cos[b z1] - 1/2 Cos[b z1] Cos[t]) Cosh[b (L - z1)] - 
       b^2 Sin[b (L - z1)] (-(1/2) Sin[b z1] + 1/2 Cos[t] Sin[b z1]) + 
       b^2 (-(1/2) Sin[b z1] - 1/2 Cos[t] Sin[b z1]) Sinh[
         b (L - z1)], -b^2 (1/2 Cosh[b z1] + 1/2 Cos[t] Cosh[b z1]) Sin[
         b (L - z1)] + 
       b^2 (1/2 Cosh[b z1] - 1/2 Cos[t/2]^2 Cosh[b z1] + 
          1/2 Cosh[b z1] Sin[t/2]^2) Sinh[b (L - z1)] - 
       b^2 Cos[b (L - z1)] (-(1/2) Sinh[b z1] - 1/2 Cos[t] Sinh[b z1]) + 
       b^2 Cosh[
         b (L - z1)] (1/2 Sinh[b z1] - 1/2 Cos[t] Sinh[b z1]), -b^2 Cos[
         b (L - z1)] (-(1/2) Cosh[b z1] - 1/2 Cos[t] Cosh[b z1]) + 
       b^2 Cosh[b (L - z1)] (1/2 Cosh[b z1] - 1/2 Cos[t] Cosh[b z1]) - 
       b^2 Sin[b (L - z1)] (1/2 Sinh[b z1] + 1/2 Cos[t] Sinh[b z1]) + 
       b^2 Sinh[
         b (L - z1)] (1/2 Sinh[b z1] - 1/2 Cos[t/2]^2 Sinh[b z1] + 
          1/2 Sin[t/2]^2 Sinh[b z1]), -(1/2) b^2 Cos[b (L - z1)] Cos[
         a b^2 z1] Sin[t] + 
       1/2 b^2 Cos[a b^2 z1] Cosh[b (L - z1)] Sin[t] + (
       a A b L^2 Sin[b (L - z1)] Sin[a b^2 z1] Sin[t])/(2 Iyy) + (
       a A b L^2 Sin[a b^2 z1] Sin[t] Sinh[b (L - z1)])/(
       2 Iyy), -((a A b L^2 Cos[a b^2 z1] Sin[b (L - z1)] Sin[t])/(
        2 Iyy)) - 1/2 b^2 Cos[b (L - z1)] Sin[a b^2 z1] Sin[t] + 
       1/2 b^2 Cosh[b (L - z1)] Sin[a b^2 z1] Sin[t] - (
       a A b L^2 Cos[a b^2 z1] Sin[t] Sinh[b (L - z1)])/(
       2 Iyy)}, {-b^2 (1/2 Cos[b z1] - 1/2 Cos[b z1] Cos[t]) Sin[
         b (L - z1)] + 
       b^2 Cosh[b (L - z1)] (-(1/2) Sin[b z1] - 1/2 Cos[t] Sin[b z1]) - 
       b^2 Cos[b (L - z1)] (1/2 Sin[b z1] - 1/2 Cos[t] Sin[b z1]) + 
       b^2 (1/2 Cos[b z1] + 1/2 Cos[b z1] Cos[t]) Sinh[
         b (L - z1)], -b^2 Cos[
         b (L - z1)] (1/2 Cos[b z1] - 1/2 Cos[b z1] Cos[t]) + 
       b^2 (-(1/2) Cos[b z1] - 1/2 Cos[b z1] Cos[t]) Cosh[b (L - z1)] - 
       b^2 Sin[b (L - z1)] (-(1/2) Sin[b z1] + 1/2 Cos[t] Sin[b z1]) + 
       b^2 (-(1/2) Sin[b z1] - 1/2 Cos[t] Sin[b z1]) Sinh[
         b (L - z1)], -b^2 (1/2 Cosh[b z1] + 1/2 Cos[t] Cosh[b z1]) Sin[
         b (L - z1)] + 
       b^2 (1/2 Cosh[b z1] - 1/2 Cos[t/2]^2 Cosh[b z1] + 
          1/2 Cosh[b z1] Sin[t/2]^2) Sinh[b (L - z1)] - 
       b^2 Cos[b (L - z1)] (-(1/2) Sinh[b z1] - 1/2 Cos[t] Sinh[b z1]) + 
       b^2 Cosh[
         b (L - z1)] (1/2 Sinh[b z1] - 1/2 Cos[t] Sinh[b z1]), -b^2 Cos[
         b (L - z1)] (-(1/2) Cosh[b z1] - 1/2 Cos[t] Cosh[b z1]) + 
       b^2 Cosh[b (L - z1)] (1/2 Cosh[b z1] - 1/2 Cos[t] Cosh[b z1]) - 
       b^2 Sin[b (L - z1)] (1/2 Sinh[b z1] + 1/2 Cos[t] Sinh[b z1]) + 
       b^2 Sinh[
         b (L - z1)] (1/2 Sinh[b z1] - 1/2 Cos[t/2]^2 Sinh[b z1] + 
          1/2 Sin[t/2]^2 Sinh[b z1]), -(1/2) b^2 Cos[b (L - z1)] Cos[
         a b^2 z1] Sin[t] + 
       1/2 b^2 Cos[a b^2 z1] Cosh[b (L - z1)] Sin[t] + (
       a A b L^2 Sin[b (L - z1)] Sin[a b^2 z1] Sin[t])/(2 Iyy) + (
       a A b L^2 Sin[a b^2 z1] Sin[t] Sinh[b (L - z1)])/(
       2 Iyy), -((a A b L^2 Cos[a b^2 z1] Sin[b (L - z1)] Sin[t])/(
        2 Iyy)) - 1/2 b^2 Cos[b (L - z1)] Sin[a b^2 z1] Sin[t] + 
       1/2 b^2 Cosh[b (L - z1)] Sin[a b^2 z1] Sin[t] - (
       a A b L^2 Cos[a b^2 z1] Sin[t] Sinh[b (L - z1)])/(2 Iyy)}};
    Dimensions[R]
    MatrixForm[R];
    R = Drop[R, {}, {2, 4, 5}];
    MatrixForm[R]
    Dimensions[R]

I have a matrix R with dimension 3*6, I want to delete columns (2, 4, 5). I tried Drop, but it seems like it is not working. The matrix is reducing to dimension 3*5. Drop works for a matrix containing numbers, but not working well if the matrix consists of symbolic variables.

How do I overcome this?

Also, I tried DeleteCases and Delete, but I still did not get what I wanted.

Mathematica is not giving an error messsage, but the answer it is giving is wrong.

$\endgroup$

closed as off-topic by m_goldberg, José Antonio Díaz Navas, MarcoB, Yves Klett, rhermans Aug 31 '18 at 8:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, José Antonio Díaz Navas, MarcoB, Yves Klett, rhermans
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Why don't you give simply R = Array[r, {3,6}] as a minima example? $\endgroup$ – Henrik Schumacher Aug 24 '18 at 18:57
  • 2
    $\begingroup$ The syntax Drop[R, {}, {2, 4, 5}] tells Mathematica to drop colums 2 to 4 in steps of 5. Since 2+5>4, only column 2 is dropped. $\endgroup$ – Henrik Schumacher Aug 24 '18 at 19:03
  • $\begingroup$ I know drop function is working for a matrix with the number. But for a matrix with symbols, it is not working. That is why I put everything in the question. $\endgroup$ – acoustics Aug 24 '18 at 19:05
  • $\begingroup$ No, there is no difference in the behavior for matrices with or without symbols. $\endgroup$ – Henrik Schumacher Aug 24 '18 at 19:07
  • $\begingroup$ sorry my mistake, I did not understand the syntax properly. $\endgroup$ – acoustics Aug 24 '18 at 19:11
8
$\begingroup$

The syntax Drop[R, {}, {2, 4, 5}] tells Mathematica to drop colums 2 to 4 in steps of 5. Since 2+5>4, only column 2 is dropped.

What you want to do can be done, for example, with

R[[All, Complement[Range[Dimensions[R][[2]]], {2, 4, 5}]]]

or

R[[All, {1,3,6}]]
$\endgroup$
7
$\begingroup$

Here are some formulations that allow you to work in terms of the column indexes of the columns you want to delete, rather than their complement.

Let r be defined by

r = Array[a, {3, 6}]
{{a[1, 1], a[1, 2], a[1, 3], a[1, 4], a[1, 5], a[1, 6]}, 
 {a[2, 1], a[2, 2], a[2, 3], a[2, 4], a[2, 5], a[2, 6]}, 
 {a[3, 1], a[3, 2], a[3, 3], a[3, 4], a[3, 5], a[3, 6]}}

Then evaluating any of follow expressions

ReplacePart[r, {_, 2 | 4 | 5} -> Nothing]
Delete[{{2}, {4}, {5}}] /@ r
MapAt[Nothing, {{2}, {4}, {5}}] /@ r

will give

{{a[1, 1], a[1, 3], a[1, 6]}, 
 {a[2, 1], a[2, 3], a[2, 6]}, 
 {a[3, 1], a[3, 3], a[3, 6]}}
$\endgroup$
  • 1
    $\begingroup$ Nice! (+1) As a side remark: It might not be relevant to the OP for their matrix is rather small, but each of this method unpacks arrays. $\endgroup$ – Henrik Schumacher Aug 24 '18 at 20:35

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