Dynamic Modeling Of Untethered Soft Flagellated Locomotion In Viscous Fluids And Granular Media