x Centroid of area between function and x-axis

5 Ansichten (letzte 30 Tage)
Blake White
Blake White am 27 Mai 2020
Kommentiert: darova am 27 Mai 2020
I've been given that xC=integral(x*Func)/integral(Func)
Also that when Func is x.^2, a=0, b=1 that xC=0.75
So I know that x*Func will be x.^3
Idk how to make y=x.^3 into a function handle so that B will work
This is where I'm at:
function xCentroid = centroid(Func,a,b)
A = integral(Func,a,b);
syms x
y = simplify (x.*Func)
B = integral(y,a,b)
xCentroid = B/A
end

Antworten (1)

darova
darova am 27 Mai 2020
Try this
f = @(x) x.^2;
f1 = @(x) x.*f(x);
A = integral(f,a,b);
B = integral(f1,a,b);
c = B/A;
  2 Kommentare
Blake White
Blake White am 27 Mai 2020
Thanks but that only works for the function being x.^2. It needs to be that any function will work so I need to be able to multiply any function by x.
darova
darova am 27 Mai 2020
Just change this line whatever you want
f = @(x) x.^2;

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by