Accuracy of integral function.
조회 수: 14(최근 30일)
I am solving a long equation with q,k,phi,D are constants and x variable. I am using the the matlab keyword "integral" to integrate the equation. when I vary D from 10^-3 to 10^-5, I am supposed to get the final answer rho_ap vary from ~1 to ~0. However in my matlab code it gived my a fixed value of 1 when ever i vary D. Is the way i calculate my integration accurate. How accurate is integral function in matlab.
% definition of constants
f = @(x) (4*k/q)*( atanh(tanh(q*phi/(4*k))*exp(-x/Lb)) + atanh(tanh(q*phi/(4*k))*exp(-(d-x)/Lb)));
John D'Errico 2017년 3월 1일
편집: John D'Errico 2017년 3월 1일
Sometimes we need to apply common sense. Is this the accuracy of the integral function, or something else?
WHENEVER you try to do an integration, optimization, anything, PLOT what you have. LOOK AT IT. Apply critical thought to what you have done so far. Just common sense. Don't just throw it into integral, and then wonder about the result.
You are integrating from 0 to d/2. So plot it over that domain.
Your function is essentially constant at 1 over that domain. Integral has no problem integrating the number 1 over any domain that you wish. This has absolutely nothing to do with integral, or the accuracy thereof.
In fact, if you look very carefully at the result of fun, it is IDENTICAL to 1 over that entire domain, down to the least significant bit of the result.
So you need to sit down and look more carefully at your function as you wrote it. If the computation is indeed correct, then you need to consider if what you are trying to do makes sense. If everything checks out, then you need to consider if it is possible to evaluate what you have written in double precision arithmetic. But if it is not possible to do so, then you need to rethink what you are doing.
Again. Common sense. NEVER just throw something at a utility without thinking about what you did, and if what you did makes any sense at all. Always plot anything that you can. If you can't plot it, then find some way to look at it. Does it make sense? Computers don't think for you, at least not yet. And once they start doing that, we may all be in trouble. Computers do exactly as you tell them to do, regardless of whether it is nonsensical.
Edit: here is a hint: LOOOK CAREFULLY at your constants. Think about them.
What is the argument to the tan function?
Yes, that small of a number. Of course, then you multiply it by
where x is no larger than d/2.
So the product is even smaller.
All of this is highly likely to produce meaningless garbage when computed in double precision arithmetic. Is it even correct? That I cannot know.
Roger Stafford 2017년 3월 1일
I see an error. The line
f = @(x) (4*k/q)*( atan(tan(q*phi/4*k)*exp(-x/Lb))+ atan(tan(q*phi/4*k)*exp(-(d-x)/Lb)))
f = @(x) (4*k/q)*( atan(tan(q*phi/(4*k))*exp(-x/Lb))+ atan(tan(q*phi/(4*k))*exp(-(d-x)/Lb)))
You were multiplying by k rather than dividing by it.