integrating equations obtained from polyfit

조회 수: 7 (최근 30일)
davood
davood 2014년 1월 14일
댓글: Bjorn Gustavsson 2014년 1월 15일
Hello,
I have an equation to integrate:
exp(thata(x)-1)*y_f(x)
But I used polyfit to get the theta and the y_f, so i have two vectors. but I want the equation version of the fit, so that I can put it on the integral equation. how can i use those two vectors to be able to compute that integral?
If someone knows how to do this, I'd appreciate the help!
thank you

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2014년 1월 15일
Well, either you can hope that your function exp(theta(x)-1)*f(x) has an explicit integral (which might be a stretch) and build yourself a symbolic version of the function and then try the integration-power of the symbolic toolbox. Or you could go with matlabs quadrature functions:
quadgk(@(x) exp(polyval(theta_p,x)-1).*polyval(f,x),0,x_star)
That should work provided your function isn't too obscure.
HTH
  댓글 수: 2
davood
davood 2014년 1월 15일
thank you so much. i checked, it seems that my function does not have an explicit integral. using quadgk is great, but it gives me:
(the value of the integral at x_star)-(the value of the integral at 0)
but i only need the value of the integral at x_star. can i do anything about it?
Bjorn Gustavsson
Bjorn Gustavsson 2014년 1월 15일
I don't know how to calculate a unique value of an integral at one point only, primitive functions typically have a constant-of-integration, for example f(x) = x^2 -> F(x) = x^3/3 + C. Maybe something is missing in your problem description?

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

추가 답변 (1개)

Mischa Kim
Mischa Kim 2014년 1월 14일
편집: Mischa Kim 2014년 1월 14일
trapz(x, exp(theta_x - 1).*y_fx)
where theta_x and y_fx are your two vectors.
  댓글 수: 2
davood
davood 2014년 1월 15일
Hi, thank you so much for the help. I'm still a little confused, though! i want to integrate that equation and then find it's value at x_star, where x_star is a constant. it seems that using trapz computes the integral numerically and does not result in an equation, which then i can find it's value at x_star. do you know how can i do this?
Mischa Kim
Mischa Kim 2014년 1월 15일
OK, but that's really a different question from the one you asked. In general, there is no way to "come up" with a reliable symbolic equation based on numeric data points. And you need a symbolic equation to be able to evaluate it at a certain x_star value.

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

카테고리

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