Area under gaussian curve

조회 수: 8 (최근 30일)
masoud avaznejad
masoud avaznejad 2020년 12월 13일
댓글: Star Strider 2020년 12월 14일
Hi guys
I want the value of area_under_curve to be exactly 30000 from 8.5 to 17
Is this way true to use integral?
Using matlab R2019b
clc;
clear;
close all;
gauss = @(x,mu,sig,amp,vo)amp*exp(-(((x-mu).^2)/(2*sig.^2)))+vo;
x = linspace(8.5,17,1000000);
mu = 12;
sig = 1.19895;
amp = 10000;
vo = 0;
gauss = gauss(x,mu,sig,amp,vo);
plot(x, gauss/1000, 'g-', 'LineWidth',.1)
gauss = @(x)amp*exp(-(((x-mu).^2)/(2*sig.^2)))+vo;
arear_under_crve = integral(gauss,8.5,17);

채택된 답변

Star Strider
Star Strider 2020년 12월 13일
Define ‘gauss’ as:
gauss = @(x,amp) amp*exp(-(((x-mu).^2)/(2*sig.^2)))+vo;
and:
arear_under_crve = @(amp) integral(@(x)gauss(x,amp),8.5,17);
then:
amp = fsolve(@(amp) arear_under_crve(amp) - 30000, 1)
produces:
amp =
9999.98895298012
.
  댓글 수: 2
masoud avaznejad
masoud avaznejad 2020년 12월 14일
Dear Star Strider
It returns amp for me in the value of 10000
And if I uses Function trapz it would be completly diffrent in asnwer!
which one is more accurate?
Star Strider
Star Strider 2020년 12월 14일
Depending on what you have set for your format, it could round up to 10000. (I used format long g to display it.) It might also give slilghtly different results with different MATLAB versions. I am using R2020b, Update 3.
I would trust the integral and fsolve result. The trapz function is useful if you have vectors you want to integrate, however integral is more accurate considering that you have defined your code in terms of functions (specifically, anonymous functions).
The trapz result would also depend on the resolution of the vectors you created from your function. The argument and function results would have to have very fine resolution (very long vectors with small increments) to equal the integral and fsolve result.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by