As you have mentioned Cuda in your question, you obviously must use a NVIDIA graphics card.
To achieve what you want, you will have to install the proprietary NVIDIA drivers and Optimus.
After that you can switch between the graphics from NVIDIA X Server Settings PRIME Profiles.
For GEFORCE 400 - 700 I recommend to install the NVIDIA drivers version 352 and nvidia-prime.
For GEFORCE 800 - 900 I recommend to install the NVIDIA drivers version 358 and nvidia-prime.
To identify the exact graphics adapter model of the external card open a terminal and execute :
lspci -k | grep -EA2 'VGA|3D'
Installation instructions - the latest stable NVIDIA drivers version 352
Highlight the Ubuntu entry in the GRUB boot menu and press the E key.
Add nouveau.modeset=0
to the end of the linux line - press F10 to boot.
On the login screen press Ctrl+Alt+F1 - enter your user name and your password - execute :
sudo apt-get update
sudo apt-get install nvidia-352 nvidia-prime
sudo reboot
Installation instructions - the latest official NVIDIA drivers version 358
Highlight the Ubuntu entry in the GRUB boot menu and press the E key.
Add nouveau.modeset=0
to the end of the linux line - press F10 to boot.
On the login screen press Ctrl+Alt+F1 - enter your user name and your password - execute :
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-358 nvidia-prime
sudo reboot
Note :
Generally you should use the drivers from the official Ubuntu repositories. Sometimes there are problems with these drivers - you can install the more current drivers from the GPU Drivers PPA. This often leads to properly working graphics, especially on very new NVIDIA GEFORCE adapters.