Scaling an array by a certain number so that the area under the curve equals a fixed number
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi friends,
Say if I have an array Pyy consisting of 1000 elements. I want the area under the curve (x, Pyy) of this array to equal a fixed number, lets call this number 30.
I would like to do this by scaling the Pyy term to create a NEW vector (PyyNEW) (scaled from Pyy) which fits this criteria, so:
trapz(x, PyyNEW) = 30
How do I achieve this? SO far I have this code but doesnt seem to work:
syms a; %create a variable to solve algebraically
for i = 1:1000;
PyyNEW(i,1) = pyy(i,1)*a;
end
eqn = trapz(x, PyyNEW, 1) == 30;
sola = solve(eqn, a);
댓글 수: 0
답변 (1개)
David Goodmanson
2020년 9월 4일
편집: David Goodmanson
2020년 9월 4일
HI Christina,
A = trapz(x,pyy) % find the unscaled area
pyy_new = pyy*(30/A);
trapz(x,pyy_new) % this will equal 30
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!