Matlab Centroid Integration PDF

Title Matlab Centroid Integration
Course Statistics
Institution Embry-Riddle Aeronautical University
Pages 3
File Size 62.6 KB
File Type PDF
Total Downloads 45
Total Views 143

Summary

Download Matlab Centroid Integration PDF


Description

ESCI201 Mat l abCent r oi dI nt egr at i on In this video we'll talk about integration in Matlab as you need to do for your discussion assignment. We'll be talking about symbolic integration, described symbolic integration using the input command in Matlab. Talk about the centroid via vertical rectangle integration mostly. Then I'll go through the sample code you're given for this discussion. Line by line. Then we'll talk about other integration methods a little bit as far as what you can do with Matlab int command. There's some difficulty understanding the difference between symbolic and numeric integration. For symbolic integration it's what you've done before you say you know integral X squared dx is X cubed over three plus C the problem with Matlab and it doesn't include the plus C when it does the integrals. It just gives you the antiderivative. You can do a definite integral also. Again symbolically zero to pi over answer that is the square root of two over six. It's not a direct number but it's square root of two over six. You can also end up with again equations as we did at the top. Numeric integration on the other hand results in a number. It's usually done by a summation. So we replace the integral with some form of summation. Now this is one of Matlab's historic strengths is it has very good and very many integration routines. Don't get called into those unless you really want to compare. Here again you would say the sum for 100 points and you end up with a number, you don't end up with a formula or anything of that nature at the end of the integration. The int command: it basically, if you would mathematically write integral X squared dx. You'd use two commands in Matlab: you'd use syms x, and that sort of tells Matlab that X is now a symbol. It's not a numeric value. It usually comes in as a one by one symbol matrix. That's OK. And then we do int X squared. And we do it with respect to X. Matlab has some defaults but it's best to spell out what you're integrating with respect to. So the X replaces the dx of the int command. And here we have another integral, a definite integral, and you can put limits on the integration. In this case now I've got a new variable T. It doesn't matter what the variable is. And we're going to do int one over T squared and we're going to integrate T. And we're going to go from one to infinity. It can even do improper integrals. And the result of this is one. Now when you do centroids. The book describes how to do centroids by integration. We'll look at it again using the vertical rectangle method. There are other methods. And in this case we have a function that defines the top of the area and a function that defines the bottom of the area. And we're looking between two X values: X left and X right. And we want the centroid of the whole shape. So how do we do this? Well we need the area so we just add up all of the brown rectangles. Again their height is y-top minus y-bottom and the width is dx. So we use the integral to add up all the areas. Now the centroid of this element is X because dx is infinitely small so it doesn't matter. So the centroid of the element is X. So to do our first moment with respect to the Y axis, Q y. We integrate this X element times the volume of the element. Y-top minus y-bottom times its width. And we get our X bar or our centroid of the whole shape as Q y divided by area. We also have a Y element. Notice the Y value is going to be halfway between the top and the bottom. So we use that for our y element centroid. And again we do at similar integral now to get the first moment with respect to the x axis. Left to right and y element. Note that y-top and y-bottom are functions of X. Most of the stuff you do Y-bottom will just be zero. And likewise we have the centroid of the whole shape is this Q x over area. Now that this is really what we've been using prior sections of the chapter. Just summing the Y bar times area and divide by the total area. The same thing we do for composite shapes. Going to do a code walkthrough of a case again it's kind of a trivial case. I'm going to define my x left as zero. An x right as a. And we're going to have a rectangle that goes from our y-bottom of zero and our Y-top of B. OK. Here's the code you were given. It's not exactly the same code but you can follow along. We have the rectangle

centroid dot m new we'll use that rename it probably for whatever shape you're going to calculate the centroid of. I have a clear command to start when I- in the debugger when I have a debug stop here or break point. It will stop at that point and you can put those anywhere in your code. If you're having trouble and then step through. For scripts it's better to have a clear command to get rid of your workspace variables before you start. Normally you wouldn't have those in there. So again we want to start the symbolic processor and the way we do that is to execute the syms command with a list of symbols following it. The symbols we need for this particular problem the rectangle is just the A B and X. And you see their value it shows it's a symbol. So if I double click on A, one by one symbol and the value of that symbol is A. Not very exciting but that's what it is. And then we'll set Y equal to B. So we get a new symbol since B is a symbol. And we can check the value of Y as B. Likewise we look at the element height. Now in this case I've got zero for my Y bottom. So my Y top is just Y. So I run that. And an X element. So now we have those variables defined. We can look X elements should just be X. And why Element is B over two. Now is the integration. Again we're going to integrate our y value. Which is the height of the rectangle with respect to X. So this is dx. From zero to A. And we'll step through there. So now we'll have an area is A times B. That's the result of the integration and we can step in through the next couple of integrations. Again the X element times Y dx or da. And then we can compute the centroid of the whole shape. And the y centroid of the whole shape. Now your code has some print statements print f what that will do is print stuff down into the command window. You can specify a file. So what I'm doing here is it will print whatever text you type. And then when it comes to a percent it will print again a format S is a symbolic or a string print. And the backslash N gives it a new line. So you put that inside the text. So we see that the area below the function Y equals B. And that's between zero and a. The area results likewise and the centroids which is what we're mainly after. Now you don't have to but you can test this out. You can put in values, numeric values. Notice that A here, we're going to put A up, has a value of A. And it's a one by one symbolic. So it asked to enter the rectangle width. I'm going to use square root of five for the rectangle width. Now we can see that A has changed. It's not symbolic anymore. It is now the square root of five numeric value. Likewise. With B. Got to step this. There we go. I'm going to give it a square root of 20. When you do an input it adds this extra line after you've entered it so we can see B as a square root of 20. And we'll step and continue. And we see the area is 10 and the centroid locations numerically. And we're done. The Green Arrow is gone. There are alternate ways to do the integration which when we get into moments of inertia might be a little bit more intuitive. Instead of using vertical rectangles we'll just use a dy by dx square. So now our da is still dy dx If we were using polar coordinates it would be r d theta d r. And for the area we do a double integral. So we integrate from the bottom to the top first and then integrate from left to right. Likewise for Q y. But now we've added instead of one we've got X which is a distance from the Y axis. And Y which is a distance from the x axis. In code that would look something like this and we define our symbols. You might have more symbols like an R or or whatever depending on what your functions are integrating. So you define what is the function on the top and define what is the function on the bottom. And we integrate again integrate one with respect to Y from bottom to top then we take that result and integrate X from left to right. And for the first moment with respect to Y we changed our one to an X and for the first moment with respect to X we just change our one to Y. We can also integrate in polar coordinates. In that case are da now is r dr d theta. And we integrate from the inside radius to the outside radius. And then from theta one to theta two Q y is the same thing. But we need X and in polar coordinates, X is our cosine theta. And Y is our sine theta. Some other symbolic commands that could be useful is: simplify, sometimes what you get out of the integral is fairly long and that simplify command in Matlab is really pretty good for giving you a nice concise short expression. Double, convert the number or symbol to a number. It has to be a symbolic number. Print F is how we get output. Again the percent value is a format string. And in this case Page 2 of 3

the first variable will go to the first format string and the value of the second variable will go to the second format string. And the format strings of interest for you are percent S, which is good for printing symbolic results. It's a string. So its characters. You can use a percent F which will make it a floating point number. In this case the point four adds four decimal places to the number. And this will give you an error if your symbol is not a number. If your symbol is a number it will convert it to a floating point. Likewise percent G will convert it to a number and write it in possibly exponential it depends on what form is shorter. So it will try to write a short answer. The other value or other function of subs as we've used it here, it substitutes the values from the workspace in to the symbolic expression. So if you have an A and the symbolic expression it will substitute the value of A from the workspace into that expression.

Page 3 of 3...


Similar Free PDFs