# Getting an error "Error using erfc... Input must be real and full"

5 views (last 30 days)
Shreya on 24 Mar 2023
Edited: Dyuman Joshi on 24 Mar 2023
This code is giving the error msg "Error using erfc... Input must be real and full"
Here PR = 0.71 so "a" will be neagtive.
a=M/(PR-1)
exp(-y*sqrt(a*PR)).*erfc(eta*sqrt(PR)-sqrt(a*t))+exp(y*sqrt(a*PR)).*erfc(eta*sqrt(PR)+sqrt(a*t))
How to rectify this problem?

Walter Roberson on 24 Mar 2023
Edited: Walter Roberson on 24 Mar 2023
if a is negative and t is positive then sqrt(a*t) is square root of a negative value which is imaginary. You end up taking erfc of a complex value.

Dyuman Joshi on 24 Mar 2023
Edited: Dyuman Joshi on 24 Mar 2023
The function erfc only supports real inputs (as evident by the error) and the input to erfc here is complex.
You can either use the symbolic erfc function, which requires Symbolic Math Toolbox. Note that you need to pass the input as symbolic number or symbolic variable.
Or you can use FEX file submissions -