Ask Your Question

Markio's profile - activity

2023-08-02 10:26:00 +0200 received badge  Notable Question (source)
2023-08-02 10:26:00 +0200 received badge  Popular Question (source)
2023-08-02 10:25:13 +0200 received badge  Popular Question (source)
2023-08-02 10:24:41 +0200 received badge  Notable Question (source)
2023-08-02 10:24:41 +0200 received badge  Popular Question (source)
2022-10-25 17:50:31 +0200 received badge  Notable Question (source)
2021-02-28 11:54:58 +0200 received badge  Popular Question (source)
2019-06-09 16:07:59 +0200 commented answer construct matrix from equations

Thank you very much! Python is on my to-do list; it seems to be very useful for Sage.

2019-06-09 13:06:40 +0200 asked a question construct matrix from equations

I have derived 3 linear equations symbolically with variables C4, C5 and C6, and I would like to convert these into matrix-vector format [A][x]=[0]. I have found another question on this forum that relates to this: Turning system of linear equations into a matrix, but I don't know how to apply that in this case.

E, Iz, A, l, kt, aL, dT, N0 ,C4, C5, C6 = var('E, Iz, A, l, kt, aL, dT, N0, C4, C5, C6')
w(x) = C4*(x^3 -l*x^2) + C5*(x^4 - l^2*x^2) + C6*(x^5 - l^3*x^2)
dw(x) = diff(w(x), x, 1); dw(x)
d2w(x) = diff(w(x), x, 2); d2w(x)
V1 = 1/2*E*Iz*((d2w(x))^2); V1
V2 = 1/2*N0*((dw(x))^2); V2
V = integral(V1, x, 0, l) + integral(V2, x, 0, l); show(V.simplify())

The equations to put in matrix-vector format:

dVdC4 = diff(V, C4).collect(C4).collect(C5).collect(C6) == 0; dVdC4
2/15*(N0*l^5 + 30*E*Iz*l^3)*C4 + 1/30*(7*N0*l^6 + 240*E*Iz*l^4)*C5 + 
1/42*(13*N0*l^7 + 504*E*Iz*l^5)*C6 == 0

dVdC5 = diff(V, C5).collect(C4).collect(C5).collect(C6) == 0; dVdC5
1/30*(7*N0*l^6 + 240*E*Iz*l^4)*C4 + 4/105*(11*N0*l^7 + 441*E*Iz*l^5)*C5 + 
1/30*(17*N0*l^8 + 780*E*Iz*l^6)*C6 == 0

dVdC6 = diff(V, C6).collect(C4).collect(C5).collect(C6) == 0; dVdC6
1/42*(13*N0*l^7 + 504*E*Iz*l^5)*C4 + 1/30*(17*N0*l^8 + 780*E*Iz*l^6)*C5 + 
1/63*(49*N0*l^9 + 2592*E*Iz*l^7)*C6 == 0

Then I created the next matrix by hand; but I assume there is a smarter way to construct a matrix:

matrix1 = matrix([
[2/15*(N0*l^5 + 30*E*Iz*l^3), 1/30*(7*N0*l^6 + 240*E*Iz*l^4), 1/42*(13*N0*l^7 + 504*E*Iz*l^5)], 
[1/30*(7*N0*l^6 + 240*E*Iz*l^4), 4/105*(11*N0*l^7 + 441*E*Iz*l^5), 1/30*(17*N0*l^8 + 780*E*Iz*l^6)],
[1/42*(13*N0*l^7 + 504*E*Iz*l^5), 1/30*(17*N0*l^8 + 780*E*Iz*l^6), 1/63*(49*N0*l^9 + 2592*E*Iz*l^7)]
])
matrix1
[     2/15*N0*l^5 + 4*E*Iz*l^3      7/30*N0*l^6 + 8*E*Iz*l^4    13/42*N0*l^7 + 12*E*Iz*l^5]
[     7/30*N0*l^6 + 8*E*Iz*l^4 44/105*N0*l^7 + 84/5*E*Iz*l^5    17/30*N0*l^8 + 26*E*Iz*l^6]
[   13/42*N0*l^7 + 12*E*Iz*l^5    17/30*N0*l^8 + 26*E*Iz*l^6   7/9*N0*l^9 + 288/7*E*Iz*l^7]
2019-06-08 15:32:59 +0200 commented answer reverse y-axis graph

Thank you!

2019-06-07 08:27:13 +0200 received badge  Nice Question (source)
2019-06-06 11:40:41 +0200 asked a question reverse y-axis graph

I'm sorry for asking trivial things, but I can't find this in the reference manual. I have produced a graph by plotting a function simply by putting a minus sign in front of the function. But I actually want to reverse the axis to get positive values in the downward direction. Is it possible to achieve this? (I am unable to post the graph, because my karma < 60)

w1_plot = plot(-w1_numerical, (x,0,3000), linestyle=":", gridlines=True, legend_label='$w_1$'
2019-06-06 10:59:46 +0200 commented answer substitute variables into values

It works great! Thank you! The code gets more compact this way.

2019-06-06 09:48:17 +0200 received badge  Student (source)
2019-06-06 08:50:18 +0200 received badge  Scholar (source)
2019-06-06 01:18:35 +0200 asked a question substitute variables into values

(Edit: I have recently started with Sagemath for an engineering course I am attending. I don't have access to Maple or Mathematica, so I wanted to give Sagemath a try. I am trying to combine info and examples from several sources but sadly I don't have any experience with Python)

I am trying to use Sagemath for a mechanics problem, for which I am at first solving a DE symbolically and later on assign physical properties to the parameters and finally plot the result. (It's a 2nd order bending problem) There are quite some parameters that I have to use, some parameters have to be expressed in terms of other parameters.

A1, A2, A3, A4, K, kt, qz, qzc, l, E, I, A, al, dT, y = var('A1, A2, A3, A4, K, kt, qz, qzc, l, E, I, A, al, dT, y')
eq1 = -A3-A4*K*l+A3*cos(K*l)+A4*sin(K*l)+((qzc*l^2)/(2*K^2)) == 0
eq2 = -A3*K^2*cos(K*l)-A4*K^2*sin(K*l)+(qzc/(K^2)) == 0
solutions = solve([eq1,eq2], A3, A4)
sol = solutions [0]
sol_A3 = sol[0].rhs()
sol_A4 = sol[1].rhs()
sol_A3

1/2*(2*K*l - (K^2*l^2 + 2)*sin(K*l))*qzc/(K^5*l*cos(K*l) - K^4*sin(K*l))

sol_A4

1/2*((K^2*l^2 + 2)*cos(K*l) - 2)*qzc/(K^5*l*cos(K*l) - K^4*sin(K*l))

w2 = function('w2')(x)
w2 = -sol_A3 - sol_A4*K*x + sol_A3*cos(K*x) + sol_A4*sin(K*x) + (qzc*x^2)/(2*K^2)
w2

-1/2*((K^2*l^2 + 2)*cos(K*l) - 2)*K*qzc*x/(K^5*l*cos(K*l) - K^4*sin(K*l)) + 1/2*(2*K*l - (K^2*l^2 + 2)*sin(K*l))*qzc*cos(K*x)/(K^5*l*cos(K*l) - K^4*sin(K*l)) + 1/2*((K^2*l^2 + 2)*cos(K*l) - 2)*qzc*sin(K*x)/(K^5*l*cos(K*l) - K^4*sin(K*l)) - 1/2*(2*K*l - (K^2*l^2 + 2)*sin(K*l))*qzc/(K^5*l*cos(K*l) - K^4*sin(K*l)) + 1/2*qzc*x^2/K^2

From this point on I want to assign values to variables, and express variables by means of other variables.

E = 21*10^4
I = 349*10^4
A = 2120
l = 3000
al = 11*10^(-6)
qz = 15
dT = 100
kt = (A*E)/l
qzc = qz/(E*I)
K = sqrt((al*dT*A*kt*l)/((E*A+kt*l)*I))
w2_intermediate = -sol_A3 - sol_A4*K*x + sol_A3*cos(K*x) + sol_A4*sin(K*x) + (qzc*x^2)/(2*K^2)
w2_intermediate

-1/2000*sqrt(583/1745)*((K^2*l^2 + 2)*cos(K*l) - 2)*qzc*x/(K^5*l*cos(K*l) - K^4*sin(K*l)) + 1/32648*x^2 + 1/2*(2*K*l -      (K^2*l^2 + 2)*sin(K*l))*qzc*cos(1/1000*sqrt(583/1745)*x)/(K^5*l*cos(K*l) - K^4*sin(K*l)) + 1/2*((K^2*l^2 + 2)*cos(K*l) - 2)*qzc*sin(1/1000*sqrt(583/1745)*x)/(K^5*l*cos(K*l) - K^4*sin(K*l)) - 1/2*(2*K*l - (K^2*l^2 + 2)*sin(K*l))*qzc/(K^5*l*cos(K*l) - K^4*sin(K*l))

I don't know how to substitute the kt, qzc and the K's in this function.

2019-06-05 12:52:52 +0200 commented answer How to use equation solutions returned by `solve`?

Thank you very much, I will try these out.

2019-06-05 12:49:48 +0200 received badge  Editor (source)
2019-06-05 12:22:40 +0200 asked a question How to use equation solutions returned by `solve`?

While obtaining the answer for A3 and A3 in a set of equations, the answer is in vector-format(??). I want to use these answer further on. How can I pick these values? Right now I just copy and paste the answer but that's not ideal.


IN:

eq1=-A3-A4*K*l+A3*cos(K*l)+A4*sin(K*l)+((qzc*l^2)/(2*K^2))==0

eq2=-A3*K^2*cos(K*l)-A4*K^2*sin(K*l)+(qzc/(K^2))==0

solve([eq1,eq2],A3,A4)

OUT:

[[A3 == 1/2*(2*K*l - (K^2*l^2 + 2)*sin(K*l))*qzc/(K^5*l*cos(K*l) - K^4*sin(K*l)), A4 == 1/2*((K^2*l^2 + 2)*cos(K*l) - 2)*qzc/(K^5*l*cos(K*l) - K^4*sin(K*l))]]


How to get A3=... and A4=...