Added raise ValueError when no func or grad is supplied.