## Take-Home Exam 1 Related

Post questions related to take-home exam 1 here.

### Re: Take-Home Exam 1 Related

Dan,

I experienced some difficulties implementing the new code you provided for the function handles in that email last week. Here's what I'd suggest:

Declare time t as a symbolic object first (otherwise Matlab will say: "Error using ==> eval, Undefined function or variable 't'."):

Then, replace

by

to suppress Matlab's warning (in R2010b) that char/diff will be replaced in future releases.

I hope this helps some of you. Please feel free to comment on that.

Thanks,

Markus

I experienced some difficulties implementing the new code you provided for the function handles in that email last week. Here's what I'd suggest:

Declare time t as a symbolic object first (otherwise Matlab will say: "Error using ==> eval, Undefined function or variable 't'."):

Then, replace

by

to suppress Matlab's warning (in R2010b) that char/diff will be replaced in future releases.

I hope this helps some of you. Please feel free to comment on that.

Thanks,

Markus

### Re: Take-Home Exam 1 Related

I did the same thing Marcus did.

Csym = sym(Cstr);

C = matlabFunction(Csym);

CPrimeSym = diff(Csym);

CPrime = matlabFunction(CPrimeSym);

CDblPrimeSym = diff(diff(Csym));

CDblPrime = matlabFunction(CDblPrimeSym);

Note: this still doesn't solve the error when you try and take CDblPrime(t) when CDblPrime is a constant.

Csym = sym(Cstr);

C = matlabFunction(Csym);

CPrimeSym = diff(Csym);

CPrime = matlabFunction(CPrimeSym);

CDblPrimeSym = diff(diff(Csym));

CDblPrime = matlabFunction(CDblPrimeSym);

Note: this still doesn't solve the error when you try and take CDblPrime(t) when CDblPrime is a constant.

### Re: Take-Home Exam 1 Related

I posted this on a different thread as well. I sent you this email but unfortunately unbeknownst to me the email didn't reach you:

To All:

I owed you some MATLAB code that was able to properly handle functions of time “t”. The solution I provided in class worked for all functions except for polynomials of degree 2 or less. Here’s a solution that takes care of that case as well (copy and paste in MATLAB):

yourStringThatDefinesC='2*t+1'

cFunction = eval(yourStringThatDefinesC)

cFunctionPrime = diff(yourStringThatDefinesC)

cFunctionPrimePrime = diff(diff(yourStringThatDefinesC))

functionHandleValue = matlabFunction(cFunction)

functionHandleFirstDeriv = matlabFunction(cFunctionPrime)

functionHandleSecondDeriv = matlabFunction(cFunctionPrimePrime)

% say that now you want to evaluate the functions at t=3:

value_tEQ3 = subs(functionHandleValue, 3)

firstDeriv_tEQ3 = subs(functionHandleFirstDeriv, 3)

secondDeriv_tEQ3 = subs(functionHandleSecondDeriv, 3)

This should do the trick.

There are other solutions that symbolically differentiate C(t) *each* time you call for the first partial derivative or second partial derivative of C(t). But this is *extremely* slow because symbolic differentiation is expensive. The solution provided above does the required symbolic differentiations *once*, then uses the result to quickly evaluate through function handlers the value, first partial derivative, or second partial derivative of C(t).

See you in class, have a good day,

Dan

To All:

I owed you some MATLAB code that was able to properly handle functions of time “t”. The solution I provided in class worked for all functions except for polynomials of degree 2 or less. Here’s a solution that takes care of that case as well (copy and paste in MATLAB):

yourStringThatDefinesC='2*t+1'

cFunction = eval(yourStringThatDefinesC)

cFunctionPrime = diff(yourStringThatDefinesC)

cFunctionPrimePrime = diff(diff(yourStringThatDefinesC))

functionHandleValue = matlabFunction(cFunction)

functionHandleFirstDeriv = matlabFunction(cFunctionPrime)

functionHandleSecondDeriv = matlabFunction(cFunctionPrimePrime)

% say that now you want to evaluate the functions at t=3:

value_tEQ3 = subs(functionHandleValue, 3)

firstDeriv_tEQ3 = subs(functionHandleFirstDeriv, 3)

secondDeriv_tEQ3 = subs(functionHandleSecondDeriv, 3)

This should do the trick.

There are other solutions that symbolically differentiate C(t) *each* time you call for the first partial derivative or second partial derivative of C(t). But this is *extremely* slow because symbolic differentiation is expensive. The solution provided above does the required symbolic differentiations *once*, then uses the result to quickly evaluate through function handlers the value, first partial derivative, or second partial derivative of C(t).

See you in class, have a good day,

Dan

### Re: Take-Home Exam 1 Related

Hello Guys

I used prof's approach except that I checked for '0' explicitly to avoid the exception from matlab.. i.e if it is '0' then I will not add the contribution otherwise I will evaluate and add..

Regards

Vaidy

I used prof's approach except that I checked for '0' explicitly to avoid the exception from matlab.. i.e if it is '0' then I will not add the contribution otherwise I will evaluate and add..

Regards

Vaidy

### Re: Take-Home Exam 1 Related

Hello Prof. Dan

1. I just realized that I am not making use of some of the inputs in the calculation like Mass, JBar, xPGround and yPGround (although I am reading them). I think mass and Jbar comes in to picture only in dynamics. But, I am not sure where I should use xPground and yPground. I guess they are the coordinates of the point at which the user is specifying the absolute x and y constraint in global coordinates. For the pendulum problem they are zero and I guess it make no difference - but my question is what should be done in general?

2. Also, should we sort the constraints based on its id and then perform the analysis so that we get the generalized coordinates as per the required order (again for the pendulum problem - the constraints are already in order, so not a problem - but in general what should we do?)

Thanks & Regards

Vaidy

1. I just realized that I am not making use of some of the inputs in the calculation like Mass, JBar, xPGround and yPGround (although I am reading them). I think mass and Jbar comes in to picture only in dynamics. But, I am not sure where I should use xPground and yPground. I guess they are the coordinates of the point at which the user is specifying the absolute x and y constraint in global coordinates. For the pendulum problem they are zero and I guess it make no difference - but my question is what should be done in general?

2. Also, should we sort the constraints based on its id and then perform the analysis so that we get the generalized coordinates as per the required order (again for the pendulum problem - the constraints are already in order, so not a problem - but in general what should we do?)

Thanks & Regards

Vaidy

### Re: Take-Home Exam 1 Related

ME451Vaidyanathan wrote:1. I just realized that I am not making use of some of the inputs in the calculation like Mass, JBar, xPGround and yPGround (although I am reading them). I think mass and Jbar comes in to picture only in dynamics. But, I am not sure where I should use xPground and yPground. I guess they are the coordinates of the point at which the user is specifying the absolute x and y constraint in global coordinates. For the pendulum problem they are zero and I guess it make no difference - but my question is what should be done in general?

2. Also, should we sort the constraints based on its id and then perform the analysis so that we get the generalized coordinates as per the required order (again for the pendulum problem - the constraints are already in order, so not a problem - but in general what should we do?)

For 1:

Mass, JBar - needed for dynamics

xPground and yPground - as the comment in the file suggests, they are the points that enter the definition of the absolute constraint: xPbody_i - xPground=C(t).

For 2:

That's not necessary but it doesn't hurt either. Moreover, there is no relation between the order of the constraints and the generalized coordinates order. Changing the order of the constraints is like changing the order of the equations in a system of nonlinear equations: it doesn't change the solution.

When it comes to the order of the generalized coordinates, the columns of the Jacobian should be in sync with the order of your generalized coordinates in the q array.

I hope this helps.

Dan

Last edited by Anonymous on Sat Nov 06, 2010 6:58 am, edited 1 time in total.

### Re: Take-Home Exam 1 Related

for the NOTE:

it said

NOTE: the outcome of the simulation using simEngine2D should be a file called pendulum.res

Do you want file as as text format like this?

save('pendulum.res', 'time', 'position', 'velocity','acceleration');

type pendulum.txt;

it said

NOTE: the outcome of the simulation using simEngine2D should be a file called pendulum.res

Do you want file as as text format like this?

save('pendulum.res', 'time', 'position', 'velocity','acceleration');

type pendulum.txt;

### Re: Take-Home Exam 1 Related

I'm a little confused about the given initial velocities x_dot, y_dot, and theta_dot.

In my code I am determining these values at t=zero by solving the velocity problem. In other words I don't need them to be given.

Any help would be greatly appreciated,

Wa'el

In my code I am determining these values at t=zero by solving the velocity problem. In other words I don't need them to be given.

Any help would be greatly appreciated,

Wa'el

Bob Dylan is God

### Re: Take-Home Exam 1 Related

Hello Prof. Dan

Thanks for the clarifications.. but, I am still confused about the xPGround and yPGround - I couldn't find that in Eq 3.5.1 or 3.5.2 (in the textbook). However, if we implement absolute constraint as a special case of relative constraint - then I can relate to what you are saying (i.e. Eq 3.5.5 and Eq 3.5.6). So, does that imply we need to implement absolute x & y constraints only as a special case of relative x and y constraint?

Thanks & Regards

Vaidy

Thanks for the clarifications.. but, I am still confused about the xPGround and yPGround - I couldn't find that in Eq 3.5.1 or 3.5.2 (in the textbook). However, if we implement absolute constraint as a special case of relative constraint - then I can relate to what you are saying (i.e. Eq 3.5.5 and Eq 3.5.6). So, does that imply we need to implement absolute x & y constraints only as a special case of relative x and y constraint?

Thanks & Regards

Vaidy

### Re: Take-Home Exam 1 Related

In part 2 of the exam - you say:

"Write additional MATLAB code that augments simEngine2D so that it is capable of carrying out Position Analysis of an arbitrary 2D mechanism"

By "arbitrary" do you mean to say that we should support all types of constraints (9 in total - Absolute/Relative X,Y,Angle,Distance Constraints + Translational Joint) or support for multiple bodies or both?

Right now my code supports multiple bodies + Reading / formulation for 3 constraints (Absolute X/Y/Angle) + Support for reading in other types of constraints from .ADM file (with no support for formulation of equations for these 6 constraints alone) - Is this good enough?

"Write additional MATLAB code that augments simEngine2D so that it is capable of carrying out Position Analysis of an arbitrary 2D mechanism"

By "arbitrary" do you mean to say that we should support all types of constraints (9 in total - Absolute/Relative X,Y,Angle,Distance Constraints + Translational Joint) or support for multiple bodies or both?

Right now my code supports multiple bodies + Reading / formulation for 3 constraints (Absolute X/Y/Angle) + Support for reading in other types of constraints from .ADM file (with no support for formulation of equations for these 6 constraints alone) - Is this good enough?

### Re: Take-Home Exam 1 Related

ME451Kuya wrote:for the NOTE:

it said

NOTE: the outcome of the simulation using simEngine2D should be a file called pendulum.res

Do you want file as as text format like this?

save('pendulum.res', 'time', 'position', 'velocity','acceleration');

type pendulum.txt;

Kuya - that would be good.

dan

### Re: Take-Home Exam 1 Related

Wa'el wrote:I'm a little confused about the given initial velocities x_dot, y_dot, and theta_dot.

In my code I am determining these values at t=zero by solving the velocity problem. In other words I don't need them to be given.

Any help would be greatly appreciated,

Wa'el

Wa'el - those are there for when you do Dynamics analysis and specify the initial configuration of the body at time t_0. For Kinematics you don't need them (like you don't need the mass moment of inertia or the mass of the body, for that matter). For now, what you did is the right thing to do. If you want, take them as a starting point for when you carry out the Position Analysis.

Dan

### Re: Take-Home Exam 1 Related

ME451Vaidyanathan wrote:Hello Prof. Dan

Thanks for the clarifications.. but, I am still confused about the xPGround and yPGround - I couldn't find that in Eq 3.5.1 or 3.5.2 (in the textbook). However, if we implement absolute constraint as a special case of relative constraint - then I can relate to what you are saying (i.e. Eq 3.5.5 and Eq 3.5.6). So, does that imply we need to implement absolute x & y constraints only as a special case of relative x and y constraint?

Thanks & Regards

Vaidy

Vaidy,

I thought of them as a particular case of the relative constraint. Yet, you don't have to implement them like that, either way is fine. Do it the way it makes most sense to you and the way it fits best with your code design.

Dan

16 posts
• Page

**1**of**2**•**1**, 2Return to ME451 Fall 2010: Kinematics and Dynamics of Machine Systems

### Who is online

Users browsing this forum: No registered users and 1 guest