Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Define a function of x and an index

Status
Not open for further replies.

ahammack

Mechanical
Apr 25, 2014
1
I have the following code. I'm trying to create two matrices that involve derivatives of a function where I am looping through counters i and j. I've tried many ways to define the functions and derivatives, but I keep getting errors. I've defined the functions just ahead of the for loops. Does anyone see what is wrong with my function definitions and function calls in the for loops?

%%%%%%%%%% Matlab Code %%%%%%

L=2;
Eb=70e9; % modulus of elasticity
rhob=2700; % density
dout=0.1;
thick=0.002;
Ab=(pi/4)*((dout^2)-((dout-(2*thick))^2));
rhoA=rhob*Ab;
Ib=(pi/64)*((dout^4)-((dout-(2*thick))^4));
EI=Eb*Ib;
kt=3000;
M=2;
N=2;
syms x;
U(x,i)=(x/L)^(i+1);
dU(x,i)=diff((x/L)^(i+1),x);
dU2(x,i)=diff((x/L)^(i+1),x,2);
% U(x,i)=(x/L)^(i+1);
% dU(x,i)=diff((x/L)^(i+1),x);
% dU2(x,i)=diff((x/L)^(i+1),x,2);
% U @x =(x/L)^(i+1);
% dU @x =diff((x/L)^(i+1),x);
% dU2 @x =diff((x/L)^(i+1),x,2);
for i=1:N,

for j=1:N,

kmat(i,j)=EI*int(dU2(x,i)*dU2(x,j),x=0..L)+(kt*dU(L,i)*dU(L,j));

mmat(i,j)=rhoA*int(U(x,i)*U(x,j),x=0..L)+(M*U(L,i)*U(L,j));

end

end
 
Replies continue below

Recommended for you

Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top