Help with Difference Equation in MATLAB

5 views (last 30 days)
Hi, all
I have a structural engineering book dated back at 1979 that presents a fairly odd equation to compute rotations at member joints.
This is:
Where C, V , h and K are constant properties. Theta is the joint rotation at the level considered, the level above and the level below (hence the subscript).
The book mentions a several ways of solving it. One being iteration procedures. It also refers to this equation as a difference equation, which I have no experience with at all. Although I have read that they are fairly similar to differential equations which i have some experience with.
My question is, is there a function or command in MATLAB that could be employed to solve this equation? Like there is for differential equations symbolically and numerically. And could somebody help me with this?
Many thanks,
Scott
  3 Comments
Torsten
Torsten on 17 Aug 2025
Edited: Torsten on 17 Aug 2025
(18) defines a linear system of equations with a tridiagonal coefficient matrix. This is confirmed by what is written in the first paragraph of 5.2 .
The paper is very old - thus solution of linear systems of equations was not standard at the time when it was published.
So if you write the equations in the form
A*theta = b
with A being a 8x8 coeffient matrix, b being a 8x1 vector and theta = [theta(1);...;theta(8)] being the solution vector and solve for theta as
theta = A\b
you will get your solution.
I did this for the equations you formulated. So if they are correct, you are done.
If you want to call (18) a recurrence relation, you can do this. The solution of this recurrence is done by solving a linear system of equations.
Scott Banks
Scott Banks on 19 Aug 2025
Okay, thanks, Torsten. I will accept your answer!

Sign in to comment.

Accepted Answer

Torsten
Torsten on 16 Aug 2025
Moved: Torsten on 16 Aug 2025
If V_i, h_i, C, K and theta_0 and theta_1 are given, you can solve for theta_(i+1) and compute theta in a loop.
theta(i+1) = ((V(i)*h(i)+V(i+1)*h(i+1))/4 - K*theta(i) + C*theta(i-1))/(-C)
  4 Comments
Scott Banks
Scott Banks on 16 Aug 2025
Sorry, Torstem, I realised what I posted was rubbish.
This is how I have tried to solve the equation before. I condsider the entire frame and go joint by joint.
E = 2.0E+08;
I = 1.07E-03;
h = 3;
A = 0.0206;
C = 1/2*4*E*I/h;
G1 = E*(2*I/5 + I/3)*13;
Q = 15;
KGm = 6*G1 + C + C;
KGt = 6*G1 + C;
x1(1) = (Q*h/4)/(24*G1); % Storey 7 approximation
x2(1) = (2*Q*h/4 + Q*h/4)/(24*G1); % Storey 6 approximation
x3(1) = (3*Q*h/4 + 2*Q*h/4)/(24*G1); % Storey 5 approximation
x4(1) = (4*Q*h/4 + 3*Q*h/4)/(24*G1); % Storey 4 approximation
x5(1) = (5*Q*h/4 + 4*Q*h/4)/(24*G1); % Storey 3 approximation
x6(1) = (6*Q*h/4 + 5*Q*h/4)/(24*G1); % Storey 2 approximation
x7(1) = (7*Q*h/4 + 6*Q*h/4)/(24*G1 + 2*C); % Storey 1 approximation
x8(1) = 0;
% Start iterations....
for i = 1:10
x1(i+1) = Q*h/(4*KGt) + C/KGm*x2(i);
x2(i+1) = (Q*h + 2*Q*h)/(4*KGm) + C/KGt*x1(i) + C/KGm*x3(i);
x3(i+1) = (2*Q*h + 3*Q*h)/(4*KGm) + C/KGm*x2(i) + C/KGm*x4(i);
x4(i+1) = (3*Q*h + 4*Q*h)/(4*KGm) + C/KGm*x3(i) + C/KGm*x5(i);
x5(i+1) = (4*Q*h + 5*Q*h)/(4*KGm) + C/KGm*x4(i) + C/KGm*x6(i);
x6(i+1) = (5*Q*h + 6*Q*h)/(4*KGm) + C/KGm*x5(i) + C/KGm*x7(i);
x7(i+1) = (6*Q*h + 7*Q*h)/(4*KGm) + C/KGm*x6(i);
x8(i+1) = 0;
end
% create vector of rotations theta.
theta = [x1(end);x2(end);x3(end);x4(end);x5(end);x6(end);x7(end);x8(end)]
theta = 8×1
1.0e-04 * 0.0094 0.0276 0.0460 0.0643 0.0827 0.1011 0.1179 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
In this I made theta(i) the subject
Does this look any better you? have I done it correctly in your opinion?
Torsten
Torsten on 16 Aug 2025
Edited: Torsten on 16 Aug 2025
Your code has nothing to do with a recurrence relation. It seems that you try to solve a linear system of equations in the unknowns x1 - x8 by fixed point iteration.
You can solve it directly without iteration using the following code:
E = 2.0E+08;
I = 1.07E-03;
h = 3;
A = 0.0206;
C = 1/2*4*E*I/h;
G1 = E*(2*I/5 + I/3)*13;
Q = 15;
KGm = 6*G1 + C + C;
KGt = 6*G1 + C;
M =[1,-C/KGm,0,0,0,0,0,0;...
-C/KGt,1,-C/KGm,0,0,0,0,0;...
0,-C/KGm,1,-C/KGm,0,0,0,0;...
0,0,-C/KGm,1,-C/KGm,0,0,0;...
0,0,0,-C/KGm,1,-C/KGm,0,0;...
0,0,0,0,-C/KGm,1,-C/KGm,0;...
0,0,0,0,0,-C/KGm,1,0;...
0,0,0,0,0,0,0,1];
rhs = [Q*h/(4*KGt);...
(Q*h + 2*Q*h)/(4*KGm);...
(2*Q*h + 3*Q*h)/(4*KGm);...
(3*Q*h + 4*Q*h)/(4*KGm);...
(4*Q*h + 5*Q*h)/(4*KGm);...
(5*Q*h + 6*Q*h)/(4*KGm);...
(6*Q*h + 7*Q*h)/(4*KGm);...
0];
x = M\rhs
x = 8×1
1.0e-04 * 0.0094 0.0276 0.0460 0.0643 0.0827 0.1011 0.1179 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
I can't tell you if it's correct because I don't understand the underlying problem.

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 16 Aug 2025
Since V_i and h_i appear to vary with the index i, there is no analytical solution. (If V and h were constants, not changing with subscript, then an analytical solution will exist, and indeed, it would be not unlike the solution of a second order ODE.)
However, you can simply write a loop. You MUST know theta_0, and theta_1. Rewrite the equation, isolating theta_(i+1) on the left hand side. Now everything is known. Just compute the value of theta_(i+1) iteratively. This is no different from computing the Fibonacci numbers. Start at the beginning, and just write a loop.
If V and h are actually fixed, scalar constants that do NOT vary with the index, then the problem does indeed have a solution, and there are multiple ways you can solve for theta in an analytical form. But I won't go into the depth of explaining the solution for a case that I don't think exists at this time.
  5 Comments
Torsten
Torsten on 17 Aug 2025
Edited: Torsten on 17 Aug 2025
As said, the index i is not a recursion or iteration index, but an index for the solution variable x_i where i goes from 1 to 8. At least if we assume that your last code incorporates what you want to compute.
John D'Errico
John D'Errico on 17 Aug 2025
This is a basic Gauss-Seidel iteration scheme. As you have wrritten it, if I recall properly, it will converge if the corresponding matrix probem is diagonally dominant. That is, you will need
1 > abs(C/KGM) + abs(C/KGt)
So what do you have?
E = 2.0E+08;
I = 1.07E-03;
h = 3;
A = 0.0206;
C = 1/2*4*E*I/h;
G1 = E*(2*I/5 + I/3)*13;
Q = 15;
KGm = 6*G1 + C + C;
KGt = 6*G1 + C;
Now, what are the ratios C/KGm and C/KGt?
C/KGm
ans = 0.0114
C/KGt
ans = 0.0115
Which means the iteration scheme you propose will be (fairly rapidly) convergent. As easily however, Torsten also showed how to solve the problem using backslash.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!