hello i'm a PHD student and a new in the matlab i have a formula that i need to integrate it numerically and plot it when i tried to do this result contain the letter i and the warning message appeard
Q = quad(@myfun,0,0.693)
Q =
-0.0000 + 0.0037i
This warning message appeared Warning: Imaginary parts of complex X and/or Y arguments ignored
i don't know what should i do please help me, i will send the file.m in the attachement file

4 Kommentare

dpb
dpb am 20 Aug. 2014
Without seeing the functional form you're trying to integrate can't say much other than the evaluation as you wrote it returned a complex value. Whether that's inherent in the function or a coding error is indeterminable w/o more info.
Need the defining equation to be integrated, probably -- if there's an error in implementation wouldn't necessarily be able to tell without knowing what was intended.
shayma mohammed
shayma mohammed am 20 Aug. 2014
The problem in this part ((-0.0459*x./sqrt(x.^2-m^2))./(1-exp(0.0459*x./sqrt(x.^2-m^2)))).*sqrt(x.^2-m^2) when i integrate it the letter i appeared in the result and when i tried to plot it the warning message appeared
Thanks for your answer
Image Analyst
Image Analyst am 20 Aug. 2014
Do you want to suppress the warning, so that it does not appear, or do you want to avoid the situation that gave rise to the warning?
shayma mohammed
shayma mohammed am 21 Aug. 2014
i want to suppress the warning so that it does not appear

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Roger Stafford
Roger Stafford am 20 Aug. 2014

2 Stimmen

The range of integration you are using, 0 to 0.693, includes values which lie inside the interval, -m < x < +m, and that will give you negative values inside the square root in sqrt(x^2-m^2). The square root of a negative number does not give a real result, but is known in mathematics as an "imaginary" number. That is what the 'i' in your result indicates. Combinations of real and imaginary numbers are known as "complex" numbers. You have a complex result.
By the way, in your integrand two of the square root expressions, cancel each other out, but there is a third one left inside the exponential which is what is causing you the complex result.

3 Kommentare

shayma mohammed
shayma mohammed am 20 Aug. 2014
Bearbeitet: dpb am 20 Aug. 2014
Please because i'am new in using the matlab dose the using of quad function
>> Q = quad(@myfun,0,0.693)
means that i will integrate any formula with the upper limit is 0.693 and the lower limit is 0
Thank you very much for your answer
According to the help...
>> help quad
quad Numerically evaluate integral, adaptive Simpson quadrature.
Q = quad(FUN,A,B) tries to approximate the integral of scalar-valued
function FUN from A to B to within an error of 1.e-6 using recursive
adaptive Simpson quadrature. FUN is a function handle. The function
Y=FUN(X) should accept a vector argument X and return a vector result
Y, the integrand evaluated at each element of X.
So, basically, "yes" with the (I'd hope obvious) caveat that "any formula" will be whatever is coded in the function referenced by the passed function handle of the first argument.
shayma mohammed
shayma mohammed am 20 Aug. 2014
If m is a variable it's about 300 numbers save in a file how can i use it in the matlab thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Function Creation finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by