Center of mass - Going nuts!
Show older comments
Hello We are given a task, where we have to calculate the center of mass of an area given by 3 functions. We have to do it numerical using symbolic toolbox.
My problem is how to calculate it using a vectors and sum function. I have found the mass and the x-coordinate, but the y-coordinate are giving me trouble. My code is like this:
syms x
f1(x)=3-x;
f2(x)=x-1;
f3(x)=-x^2+4*x-1;
m=1; x1plot = 1:0.001:2; x2plot = 2:0.001:3;
M1=m*(sum(f3(x1plot))-sum(f1(x1plot)))*0.001; M2=m*(sum(f3(x2plot))-sum(f2(x2plot)))*0.001; M=M1+M2;
'The mass' vpa(M)
Xko=sum((1/M)*m*x1plot.*((f3(x1plot)-f3(x2plot))+(f1(x1plot)+f2(x2plot)))*0.001)
'x koor'
vpa(Xko)
Yk2=(f1(x1plot)-f2(x2plot)+(f3(x1plot)+f3(x2plot)))/2
Yko=sum((1/M)*m*((f3(x1plot)-f3(x2plot))+(f1(x1plot)+f2(x2plot))).*Yk2*0.001)
'Y koor' vpa(Yko)
I hope that you are able to see my problem and hopefully give me an answer. Thank you!
1 Comment
sixwwwwww
on 29 Oct 2013
I run you code and didn't get any error. Can you specify what error are you getting?
Answers (2)
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!