Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 1891. High Precision Square Root (Inspired by Project Euler 80)

Created by James

Given a positive integer n which is not a perfect square, write a MATLAB script that will calculate the square root of n truncated to k places after the decimal point. Your output should be a string. For example, the output of string_sqrt(1000,10) should be '31.6227766016' Notice that the square root of 1000 is (according to MATLAB) 31.62277660168379, so we want the integer part complete, as well as the first k numbers after the decimal point without rounding.

Several of the values of k will be larger than the usual precision shown by MATLAB, so you'll need to be inventive. Good luck.

Problem Group

Solution Statistics

6 correct solutions 4 incorrect solutions
Last solution submitted on May 20, 2014