FAQ  •  Login

Take-Home Exam 1 Related

<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Thu Nov 04, 2010 6:51 am

Take-Home Exam 1 Related

Post questions related to take-home exam 1 here.
<<

MarkusS

Newbie
Newbie

Posts: 3

Joined: Thu Oct 28, 2010 11:55 am

Unread post Thu Nov 04, 2010 1:38 pm

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'."):

  Code:
syms t;



Then, replace

  Code:
yourStringThatDefinesC = '2*t+1';


by

  Code:
yourStringThatDefinesC = sym('2*t+1');


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
<<

MarkusS

Newbie
Newbie

Posts: 3

Joined: Thu Oct 28, 2010 11:55 am

Unread post Thu Nov 04, 2010 3:24 pm

Re: Take-Home Exam 1 Related

... another thing:

  Code:
cFunction = eval(yourStringThatDefinesC)


caused some problems if say yourStringThatDefinesC = sym('0') ("Undefined function or method 'matlabFunction' for input arguments of type 'double'.")

I used

  Code:
cFunction = yourStringThatDefinesC


instead.


- Markus
<<

ME451Tyler

ME751 Student

Posts: 25

Joined: Tue Mar 02, 2010 10:19 pm

Unread post Thu Nov 04, 2010 6:40 pm

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.
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Fri Nov 05, 2010 7:03 am

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
<<

ME451Vaidyanathan

ME451 Student
ME451 Student

Posts: 8

Joined: Thu Oct 28, 2010 11:49 am

Unread post Fri Nov 05, 2010 8:37 am

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
<<

ME451Vaidyanathan

ME451 Student
ME451 Student

Posts: 8

Joined: Thu Oct 28, 2010 11:49 am

Unread post Fri Nov 05, 2010 7:08 pm

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
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Sat Nov 06, 2010 6:56 am

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.
<<

ME451Kuya

ME451 Student
ME451 Student

Posts: 1

Joined: Thu Oct 28, 2010 11:48 am

Unread post Sat Nov 06, 2010 3:56 pm

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;
<<

Wa'el

ME451 Student
ME451 Student

Posts: 7

Joined: Thu Oct 28, 2010 11:46 am

Location: Mifflin

Unread post Sat Nov 06, 2010 3:57 pm

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
Bob Dylan is God
<<

ME451Vaidyanathan

ME451 Student
ME451 Student

Posts: 8

Joined: Thu Oct 28, 2010 11:49 am

Unread post Sat Nov 06, 2010 7:18 pm

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
<<

ME451Vaidyanathan

ME451 Student
ME451 Student

Posts: 8

Joined: Thu Oct 28, 2010 11:49 am

Unread post Mon Nov 08, 2010 2:30 am

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?
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Mon Nov 08, 2010 8:13 am

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
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Mon Nov 08, 2010 8:16 am

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
<<

Dan Negrut

Global Moderator
Global Moderator

Posts: 833

Joined: Wed Sep 03, 2008 12:24 pm

Unread post Mon Nov 08, 2010 8:21 am

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
Next

Return to ME451 Fall 2010: Kinematics and Dynamics of Machine Systems

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software.