How can I solve matrix problems in MATLAB using symbolic variables?

In summary, the conversation is about two simple MATLAB questions. The first question pertains to defining symbolic variables and multiplying them with matrices, and the issue of putting one matrix into another. The second question is about making a transpose for a matrix and dealing with an error message.
  • #1
Sadeq
107
0
i have 2 simple MATLAB questions
first when i have two matrices
the first one is empty and the second one conatins numbers
i can
Say A=B
SO THE VALUE OF B BECOMES INSIDE A
BUT MY QUESTION I JUST DEFINE SYMS EI
and multiply it by B
bUT When itry to put Put B in A
IT DOENST WORK
COULD ANY ONE HELP PLEASE

THE SECOND QUESTION , WHEN i make transpose for matrix it gives me conject, so how can i deal with this
thank
 
Physics news on Phys.org
  • #2
Sadeq said:
i have 2 simple MATLAB questions
first when i have two matrices
the first one is empty and the second one conatins numbers
i can
Say A=B
SO THE VALUE OF B BECOMES INSIDE A
BUT MY QUESTION I JUST DEFINE SYMS EI
and multiply it by B
bUT When itry to put Put B in A
IT DOENST WORK
COULD ANY ONE HELP PLEASE

THE SECOND QUESTION , WHEN i make transpose for matrix it gives me conject, so how can i deal with this
thank

I have no idea what you're asking.

Also, this should be posted in the section that deals with Matlab and Mathematica, etc. I am moving your post to that section, but will leave a forwarding link.
 
  • #3
Please post your code.
 
  • #4
FIRST QUESTION
clc
clear all

T=0*pi/180;

A12=[(cos(T))^2 cos(T)*sin(T) -(cos(T))^2 -cos(T)*sin(T); cos(T)*sin(T) (sin(T))^2 -cos(T)*sin(T) -(sin(T))^2;-(cos(T))^2 -cos(T)*sin(T) (cos(T))^2 cos(T)*sin(T);-cos(T)*sin(T) -(sin(T))^2 cos(T)*sin(T) (sin(T))^2]

T=0*pi/180;
A43=[(cos(T))^2 cos(T)*sin(T) -(cos(T))^2 -cos(T)*sin(T); cos(T)*sin(T) (sin(T))^2 -cos(T)*sin(T) -(sin(T))^2;-(cos(T))^2 -cos(T)*sin(T) (cos(T))^2 cos(T)*sin(T);-cos(T)*sin(T) -(sin(T))^2 cos(T)*sin(T) (sin(T))^2]

T=90*pi/180;
A14=[(cos(T))^2 cos(T)*sin(T) -(cos(T))^2 -cos(T)*sin(T); cos(T)*sin(T) (sin(T))^2 -cos(T)*sin(T) -(sin(T))^2;-(cos(T))^2 -cos(T)*sin(T) (cos(T))^2 cos(T)*sin(T);-cos(T)*sin(T) -(sin(T))^2 cos(T)*sin(T) (sin(T))^2]

T=90*pi/180;
A23=[(cos(T))^2 cos(T)*sin(T) -(cos(T))^2 -cos(T)*sin(T); cos(T)*sin(T) (sin(T))^2 -cos(T)*sin(T) -(sin(T))^2;-(cos(T))^2 -cos(T)*sin(T) (cos(T))^2 cos(T)*sin(T);-cos(T)*sin(T) -(sin(T))^2 cos(T)*sin(T) (sin(T))^2]

T=53.13*pi/180;
A13=[(cos(T))^2 cos(T)*sin(T) -(cos(T))^2 -cos(T)*sin(T); cos(T)*sin(T) (sin(T))^2 -cos(T)*sin(T) -(sin(T))^2;-(cos(T))^2 -cos(T)*sin(T) (cos(T))^2 cos(T)*sin(T);-cos(T)*sin(T) -(sin(T))^2 cos(T)*sin(T) (sin(T))^2]

A=[zeros(8,8)]
syms EI
A12=EI.*A12./3
A43=EI.*A43./3
A14=EI.*A14./4
A23=EI.*A23./4
A13=EI.*A13./5
c=1
s=0
for i=[1 2 3 4]
for j=[1 2 3 4]
s=s+1
A(i,j)=A12(c,s)
end
c=c+1
s=0
end
c=1
s=0
for i=[1 2 7 8]
for j=[1 2 7 8]
s=s+1
A(i,j)= A(i,j)+A14(c,s)
end
c=c+1
s=0
end
c=1
s=0
for i=[7 8 5 6]
for j=[7 8 5 6]
s=s+1
A(i,j)= A(i,j)+A43(c,s)
end
c=c+1
s=0
end
c=1
s=0
for i=[3 4 5 6]
for j=[3 4 5 6]
s=s+1
A(i,j)= A(i,j)+A23(c,s)
end
c=c+1
s=0
end
c=1
s=0
for i=[1 2 5 6]
for j=[1 2 5 6]
s=s+1
A(i,j)= A(i,j)+A13(c,s)
end
c=c+1
s=0
end
b=A(2:6,2:6)
b=inv(b)
c=[0; 0; 0; 15; -20]
d=b*c
 
  • #5
This one works without ei?i don't know why
 
  • #6
this is second question
clc
clear all
syms L x W w1 %% W=w2-w1
A=[ 1 0 0 0;0 -1 0 0;-3/L^2 2/L 3/L^2 1/L;
2/L^3 -1/L^2 -2/L^3 -1/L^2]
B=A'
C=[1;x;x^2;x^3]
D=w1+W*x/L
F=C*D
E=int(F,x,0,L)
M=B*E
 
  • #7
Sadeq said:
This one works without ei?i don't know why

What is EI? AFAICT (not having Matlab) syms is a symbolic toolbox command that declares a variable to the symbolic processor and gives any variables a default value of their own names if a value is not provided. Is EI a special name for something (I believe Ei is the function name for the Exponential Integral but I can't see how that would work here)?
 
  • #8
NemoReally said:
What is EI? AFAICT (not having Matlab) syms is a symbolic toolbox command that declares a variable to the symbolic processor and gives any variables a default value of their own names if a value is not provided. Is EI a special name for something (I believe Ei is the function name for the Exponential Integral but I can't see how that would work here)?

Yes, I don't have the MATLAB symbolic toolkit either but I believe the "syms EI" is simple creating a symbolic variable with name EI.

Just to be clear SADEQ, is this the specific code that fails? When you try to assign the symbolic variable to the previously defined numeric variable A12?
syms EI
A12=EI.*A12./3
 
  • #9
Syms EI as any variable ,YOU CAN SAY X instead or anything
thr problem become when i use it in Matrix A
 
  • #10
the system will fail when i try to fill A12 in A for example
however A12 has been defined(already multipled by Varaible X, EI whatever)
 
  • #11
Sadeq said:
the system will fail when i try to fill A12 in A for example
however A12 has been defined(already multipled by Varaible X, EI whatever)
Do you have to declare all variables (including A12) using syms if you want the symbolic processor to take note of them? I think what you've asked Matlab to do is to multiply each element of (the numerically-defined) A12 by a symbolic variable EI (which should result in each element containing being a numeric value times EI (eg, 0.5*EI if the corresponding initial value an element is 1.5)

What do you expect to see?
What do you see (including any error messages)?
 
  • #12
Sadeq said:
the system will fail when i try to fill A12 in A for example
however A12 has been defined(already multipled by Varaible X, EI whatever)

Ok, so the dynamic typing handles the following commands ok. That is, it allows you to redefine the (previously) numeric variable A12 as a symbolic. It creates a symbolic variable via multiplication with an existing symbolic variable.
Code:
A=[zeros(8,8)]
syms EI
A12=EI.*A12./3
But it draws the line at this. That is, when you attempt to redefine a single entry in a (previously) numeric matrix as a symbolic (while the other entries in the matrix remain, at this time, numeric). This behavior is not all that surprising to be honest.
Code:
A(i,j)=A12(c,s)
 
  • #13
so can i define empty matrix , allowing me to enter symbolic?if yes how?
Thank you man
 
  • #14
Sadeq said:
so can i define empty matrix , allowing me to enter symbolic?if yes how?
Thank you man

Try converting the whole matrix from numeric to symbolic before you start assigning the individual symbolic entries.

For example, I think this should work.
Code:
A = zeros(8,8)
A = sym(A)
 

Related to How can I solve matrix problems in MATLAB using symbolic variables?

What is a matrix in Matlab?

A matrix in Matlab is a two-dimensional array of numbers or variables. It can be represented as a grid of rows and columns, with each element having a specific value. Matrices are commonly used in Matlab for performing mathematical operations and storing data.

How do I create a matrix in Matlab?

To create a matrix in Matlab, you can use the "matrix" function or simply assign values to a variable using square brackets. For example, "A = [1, 2, 3; 4, 5, 6]" creates a 2x3 matrix with the specified values. You can also use loops or other functions to generate matrices.

What is the difference between a matrix and an array in Matlab?

In Matlab, a matrix is a specific type of array that has two dimensions (rows and columns). Arrays can have any number of dimensions, including one-dimensional arrays (vectors) and multi-dimensional arrays. Matrices are often used for mathematical operations, while arrays can store any type of data.

How do I perform operations on matrices in Matlab?

Matlab has built-in functions for performing mathematical operations on matrices, such as addition, subtraction, multiplication, and division. You can also use operators (+, -, *, /) to perform these operations. Additionally, Matlab has functions for transposing, inverting, and reshaping matrices.

How do I solve matrix problems in Matlab?

To solve matrix problems in Matlab, you can use the built-in functions for solving systems of linear equations, finding eigenvalues and eigenvectors, and performing matrix decompositions. You can also use loops and other functions to write your own code for solving specific matrix problems.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top