I am trying to find values of four constants from four equations. Yet the code is unable to give out values

1 view (last 30 days)
Using the below code i was trying to find out values of four constants(a1,a2,a3,a4) using four equations. However, the code is unable to give out the result. Can someone help me out
clc;
clear all;
syms a1 a2 a3 a4 B x L;
syms y ;
displacement1 = a1*sin(B*x)+a2*cos(B*x)+a3*sinh(B*x)+a4*cosh(B*x);
slope1=diff(displacement1,x)
moment1=diff(slope1,x)
shear1=diff(moment1,x)
eq11=subs(moment1,x,0)
eq12=subs(shear1,x,0)
eq13=subs(displacement1,x,y);
eq14=subs(moment1,x,y),
eq11==0
eq12==0
eq13==0
eq14==0
solve(eq11,eq12,eq13,eq14,a1,a2,a3,a4)

Accepted Answer

Walter Roberson
Walter Roberson on 13 Jan 2022
When I try your code, I get all 0 for the constants.
When I go through step by step from the equations, I get the same result. eq11 forces a2==a4. eq12 forces a1==a3. Substitute appropriately in eq13 eq14 and solve the first for a2 and substitute into the last equation. a1 then appears as a linear multiplier so a1 must be 0, and everything else falls through as 0.

More Answers (2)

David Goodmanson
David Goodmanson on 13 Jan 2022
Edited: David Goodmanson on 13 Jan 2022
Hi Sahir,
you have to load this beam in some manner in order to get nonzero deflection. If all the boundary conditions are set to 0, then a1=a2=a3=a4=0 as Walter has noted. Here is an example with nonzero bc's:
clear all;
syms a1 a2 a3 a4 B x L;
syms y;
displacement1 = a1*sin(B*x)+a2*cos(B*x)+a3*sinh(B*x)+a4*cosh(B*x);
slope1=diff(displacement1,x)
moment1=diff(slope1,x)
shear1=diff(moment1,x)
eq11=subs(moment1,x,0)
eq12=subs(shear1,x,0)
eq13=subs(displacement1,x,y)
eq14=subs(moment1,x,y)
z = solve(eq11==1,eq12==2,eq13==3,eq14==4,a1,a2,a3,a4)
z.a1 % for example
ans = (4*B*cos(B*y) + 4*B*cosh(B*y) - 4*cos(B*y)*sinh(B*y) + 3*B^3*cos(B*y) ...
- 3*B^3*cosh(B*y) - 2*B*cos(B*y)*cosh(B*y))/(2*B^3*(cos(B*y)*sinh(B*y) ...
- cosh(B*y)*sin(B*y)))

John D'Errico
John D'Errico on 13 Jan 2022
Edited: John D'Errico on 13 Jan 2022
When will people learn to use vectors instead of numbering their variables? And learn to use semicolons on your lines, in the right places. syms does not need a semicolon. Oh well, these will be eternal battles. :)
Others have said this. But it really is simple. If I have a LINEAR system of equations, set equal to zero, and there are NO constant terms. That is a system that is called a homogeneous linear system, then the solution of the problem (if the matrix A is of full rank)
A*X = 0
will be all zeros for the vector X. Can we write this system as a linear homogeneous system? Well yes, we can. Each of the subsequent equations are just derivatives of the first one for displacement. And it does not matter how many times you differentiate an expression like a1*sin(B*x), with respect to x. It will still be a1*(stuff). That is, it will still be linear with respect to the unknown a1. And there will be no constant terms created, that are NOT a function of a1.
By the way, these next 4 lines effectively do NOTHING at all in MATLAB.
eq11==0
eq12==0
eq13==0
eq14==0
Those results are dumped directly into the bit bucket. MATLAB looks at what you wrote, then said to itself, hmm. they want me to set something to zero, but then they do not tell me what to do with it, just display the result on the command line. So nothing substantial happens beyond displaying a result.
Had you written this:
eq11 = eq11==0
eq12 = eq12==0
eq13 = eq13==0
eq14 = eq14==0
That would actually have done something!
Anyway, we can write ALL of these equations in a simple form. I'll let MATLAB do it for me. And I'll do it correctly.
syms a1 a2 a3 a4 B x L
syms y
displacement1 = a1*sin(B*x)+a2*cos(B*x)+a3*sinh(B*x)+a4*cosh(B*x);
slope1=diff(displacement1,x);
moment1=diff(slope1,x);
shear1=diff(moment1,x);
eq(1)=subs(moment1,x,0) == 0;
eq(2)=subs(shear1,x,0) == 0;
eq(3)=subs(displacement1,x,y) == 0;
eq(4)=subs(moment1,x,y) == 0;
As you can see, we now have 4 equations in the vector eq.
eq(:)
ans = 
Do you see that your four equations are still a LINEAR system in the unknowns a1,a2,a3,a4? We can factor out those unknowns as a vector, [a1;a2;a3;a4].
Now let MATLAB do the work. equationsToMatrix does it for me.
[A,rhs] = equationsToMatrix(eq,[a1,a2,a3,a4])
A = 
rhs = 
As long as that linear system has rank 4, then NO solution exists except the all zero solution. See there are NO constants in this, so this really is what I called a homogeneous linear system. And the matrix A has full rank. MATLAB knows that.
rank(A)
ans = 4
NO solution to that linear system can exist but the one with a1=a2=a3=a4=0. I'm sorry, but that comes from Linear Algebra 101. (Ok, maybe Linear Algebra 102. It has been a really long time since I took those classes.)
Now we can solve the linear system. The answer should be absolutely no surprise.
X = solve(eq,[a1,a2,a3,a4])
X = struct with fields:
a1: 0 a2: 0 a3: 0 a4: 0
Had you wanted to get a non-zero result, you had to put some sort of action into the system. (David points this out.) A load at some point perhaps, or a gravity load.

Community Treasure Hunt

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

Start Hunting!