×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Define a function of x and an index

Define a function of x and an index

Define a function of x and an index

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources