Thread Subject: erf(x) troubles

Subject: erf(x) troubles

From: Grant Ericson

Date: 3 Nov, 2009 18:30:24

Message: 1 of 4

Trying to plot a this function so I can thermal conductivity 'k':

close all
clear

k = -1:.05:1;

for j=1:length(k)

A(j) = erf(.295099*k(j)^-.5);
B(j) = exp(13.48325*k(j)^-1);
C(j) = erf(3.68379*k(j)^-.5);

D(j) = A(j)+B(j)-(B(j)*C(j))-(7/15);

end

plot(k,D)


However, MATLAB keeps giving me this error message:

??? Error using ==> erfcore
Input must be real.

Error in ==> erf at 21
y = erfcore(x,0);

Error in ==> ht5_76 at 11
y = erf(.295099*k(j)^-.5);

Can someone help me out? Apparently, I am not MATLAB-literate.

Thanks.

Subject: erf(x) troubles

From: TideMan

Date: 3 Nov, 2009 18:46:24

Message: 2 of 4

On Nov 4, 7:30 am, "Grant Ericson" <geric...@uncc.edu> wrote:
> Trying to plot a this function so I can thermal conductivity 'k':
>
> close all
> clear
>
> k = -1:.05:1;
>
> for j=1:length(k)
>
> A(j) = erf(.295099*k(j)^-.5);
> B(j) = exp(13.48325*k(j)^-1);
> C(j) = erf(3.68379*k(j)^-.5);
>
> D(j) = A(j)+B(j)-(B(j)*C(j))-(7/15);
>
> end
>
> plot(k,D)
>
> However, MATLAB keeps giving me this error message:
>
> ??? Error using ==> erfcore
> Input must be real.
>
> Error in ==> erf at 21
> y = erfcore(x,0);
>
> Error in ==> ht5_76 at 11
> y = erf(.295099*k(j)^-.5);
>
> Can someone help me out?  Apparently, I am not MATLAB-literate.
>
> Thanks.

Matlab is not the problem.
Your understanding of mathematics is the problem.
What happens when you take the square root of a negative number?
To demonstrate, do this in Matlab:
sqrt(-1)
You see the funny answer? That is called a complex number.
It has a real part (the first bit) and an imaginary part (the bit
multiplied by i)
The error message Matlab is giving you is that erf only works with
real numbers.

Subject: erf(x) troubles

From: Grant Ericson

Date: 3 Nov, 2009 18:58:02

Message: 3 of 4

I understand imaginary numbers. I just wasn't seeing that I was inputting imaginary numbers into the function. Time to redo my model!

Thanks.

Subject: erf(x) troubles

From: Grant Ericson

Date: 3 Nov, 2009 19:00:21

Message: 4 of 4

"Grant Ericson" <gericson@uncc.edu> wrote in message <hcpufq$hvv$1@fred.mathworks.com>...
> I understand imaginary numbers. I just wasn't seeing that I was inputting imaginary numbers into the function. Time to redo my model!
>
> Thanks.



Thermal conductivity cannot have a negative number. Dope! Should have thought about that.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com