How to obtain a matrix element in a matrix defined by a function?

I have a function as shown below:
A(xi, eta) =
conj(eta)/24 - 1/24
conj(xi)/16 - 1/16
1/24 - conj(eta)/24
- conj(xi)/16 - 1/16
conj(eta)/24 + 1/24
conj(xi)/16 + 1/16
- conj(eta)/24 - 1/24
1/16 - conj(xi)/16
In this function, I want to obtain the 3rd element of matrix i.e 1/24 - conj(eta)/24 by using the function A(3,1) but on doing so, I am obtaining the value of function at xi=3 and eta=1. How can I get the third element or any required element of the matrix?

4 Comments

"I have a function as shown below..:"
That is not a function:
It appears you have simply calculated some value/s, and allocate these to an array A.
"In this function, I want to obtain the 3rd element of matrix i.e 1/24 - conj(eta)/24 by using the function A(3,1)"
You don't have a function, just an array A. So A(3,1) is basic MATLAB indexing into an array:
It is not clear what you expect to happen, but it seems that you should actually spend some time learning basic MATLAB concepts, such as what functions are, what arrays are, how to use indexing, etc. Most of these basic concepts are introduced on the "Getting Started" tutorials:
Thank you Stephen. But I would be grateful if you could share an idea to obtain 3rd element of the array. On writing A(3,1), rather than getting 3rd element, I am getting all the arrays with the value of xi=3 and eta=1.
"On writing A(3,1), rather than getting 3rd element, I am getting all the arrays with the value of xi=3 and eta=1."
Then you will need to write a function. See the links I gave in my last comment.
Stephen, I couldn't find on which link it is mentioned. Can you please share the link again with more elaboration on how to obtain the individual function from a function array as I have provided.
% Design a RC Slab with dimension 8mx12m with fixed discontinuous ends
% system. Use M20 concrete with unit weight 25 KN/m3 and live load
% (5+CRN/100) KN/m2. Calculate stiffness matrix and stress with Midlin
% theory. Assume suitable data if necessary. CRN= Class Roll Number
clc
%obtaining the shape function with their derivative with respect to xi and
%eta
syms N1(xi,eta)
syms N2(xi,eta)
syms N3(xi,eta)
syms N4(xi,eta)
N1(xi,eta)=1/4*(1-eta)*(1-xi);
N2(xi,eta)=1/4*(1+xi)*(1-eta);
N3(xi,eta)=1/4*(1+xi)*(1+eta);
N4(xi,eta)=1/4*(1-xi)*(1+eta) ;
N1wxi=diff(N1,xi);
N1weta=diff(N1,eta);
N2wxi=diff(N2,xi);
N2weta=diff(N2,eta);
N3wxi=diff(N3,xi);
N3weta=diff(N3,eta);
N4wxi=diff(N4,xi);
N4weta=diff(N4,eta);
% disp('Let us consider the coordinate of the right bottom corner of the slab as (0,0), we get')
% A(0,0), B(12,0), C(12,8), D(0,8)
x1=0;y1=0;x2=12; y2=0; x3=12; y3=8; x4=0; y4=8;
%obtaining Jacobian Matrix elements
J11=N1wxi*x1+N2wxi*x2+N3wxi*x3+N4wxi*x4;
J12=N1wxi*y1+N2wxi*y2+N3wxi*y3+N4wxi*y4;
J21=N1weta*x1+N2weta*x2+N3weta*x3+N4weta*x4;
J22= N1weta*y1+N2weta*y2+N3weta*y3+N4weta*y4;
%Obtaining Jacobian Matrix
Jacobian=zeros(2,2);
Jacobian(1,1)=J11; Jacobian(1,2)=J12; Jacobian(2,1)=J21;Jacobian(2,2)=J22;
Jacobian
J=inv(Jacobian)
J11=J(1,1);
J12=J(1,2);
J21=J(2,1);
J22=J(2,2);
%The stiffness for the Midline Plate is prepared by combining the stiffness
%for shear and flexure
% Calculation of Stiffness for Flexure
B=[J11 J12 0 0 0 0 0 0;J21 J22 0 0 0 0 0 0;0 0 J11 J12 0 0 0 0;0 0 J21 J22 0 0 0 0;0 0 0 0 J11 J12 0 0; 0 0 0 0 J21 J22 0 0; 0 0 0 0 0 0 J11 J12; 0 0 0 0 0 0 J21 J22]
A=B*[N1wxi N1weta N2wxi N2weta N3wxi N3weta N4wxi N4weta]'
syms C(xi,eta)
At the end of this code, I am willing to get the individual function from the array A and assign to other variable. Please help me for this.

Sign in to comment.

 Accepted Answer

Nth = @(M, varargin) M(varargin{:});
After which you can
x = Nth(sum(A), 1);
There is no syntax for indexing the result of a function: there is only a way to use an auxillary function to express the indexing in expression form instead of having to always assign to a temporary variable and index that variable.

More Answers (0)

Categories

Find more on Seismology in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!