Question

In: Advanced Math

Write a user-defined MATLAB function that converts real numbers in decimal form to binary form. Name...

Write a user-defined MATLAB function that converts real numbers in decimal form to binary form. Name the function b = deciTObina (d), where the input argument d is the number to be converted and the output argument b is a 30-element-long vector with 1s and 0s that represents the number in binary form. The first 15 elements of b store the digits to the left of the decimal point, and the last 15 elements of b store the digits to the right of the decimal point. If more than 15 positions are required in the binary form for the digits to the right of the decimal point, the digits should be chopped. If the number that is entered as d is larger than can be stored in b, the function should display an error message. Use the deciTObina in the Command Window to convert the numbers 85.321, 0.00671, and 3006.42.

Solutions

Expert Solution

%%% Matlab function

function [b] = deciTObin(d)
i=15;
j=16;
dn=floor(d); %%% integer part
dd=d-dn; %%% decimal part
for n=1:15
    if (d > 2^(15))
        disp('Number is too large to store in 15 digit');
        break;
    else
        %%% Left part
       
        b(i)=mod(dn,2);
        dn=floor(dn/2);
         i=i-1;
      
        %%% right part
        dd=dd*2;
        if ( dd > 1 || dd ==1 )
            b(j)=1;
            dd=dd-1;
        else
            b(j)=0;
        end
        j=j+1;
   end
  
end

end

%%%%

clc;
clear all;
close all;
d=85.321;
b=deciTObin(d);
b'
d=0.00671;
b=deciTObin(d);
b'
d=3006.42;
b=deciTObin(d);
b'

OUTPUT:


ans =

     0
     0
     0
     0
     0
     0
     0
     0
     1
     0
     1
     0
     1
     0
     1
     0
     1
     0
     1
     0
     0
     1
     0
     0
     0
     1
     0
     1
     1
     0


ans =

     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     0
     1
     1
     0
     1
     1
     0
     1
     1


ans =

     0
     0
     0
     1
     0
     1
     1
     1
     0
     1
     1
     1
     1
     1
     0
     0
     1
     1
     0
     1
     0
     1
     1
     1
     0
     0
     0
     0
     1
     0

>>


Related Solutions

Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are...
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are not allowed to use library functions for conversion. The output should look exactly as follows: DECIMAL      BINARY                     HEXDECIMAL                      BCD 0                      0000 0000                   00                                            0000 0000 0000 1                      0000 0001                   01                                            0000 0000 0001 2                      0000 0010                   02                                            0000 0000 0010 .                       .                                   .                                               . .                       .                                   .                                               . 255                  1111 1111                   FF                                            0010 0101 0101
Please solve the following problem for MATLAB Write a user-defined function (name it F to C)...
Please solve the following problem for MATLAB Write a user-defined function (name it F to C) that converts temperature in degrees F to temperature in degrees C. Use the function to solve the following problem. The change in the length of an object, ∆L, due to a change in the temperature, ∆T, is given by: ∆L = αL∆T, where a is the coefficient of thermal expansion. Determine the change in the area of a rectangular(4.5 m by 2.25m) aluminum (α=23·10-61/˚C)...
C++ only Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This...
C++ only Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This function takes a single parameter, a non-negative integer, and returns a string corresponding to the binary representation of the given value. Your function should be named decimalToBinaryRecursive Your function should take a single argument An integer to be converted to binary Your function should not print anything Your function should use recursion instead of a loop. Note that if you try to use a...
MATLAB Write a user defined function for a projectile motion. If a ball is launched from...
MATLAB Write a user defined function for a projectile motion. If a ball is launched from initial position(0,0) with a velocity v0 at angle θ, determine your horizontal and vertical position. Please plot x vs. t, y vs. t and y vs. x.
3. Write a java method that accepts a binary number and converts it to decimal then...
3. Write a java method that accepts a binary number and converts it to decimal then display the result. For Example: (110)2 = (6)10 (2 2 *1)+ (21 *1) + (20*0) = 6 Additional task: write a method that accepts a decimal and converts it to binary. i need to solve it as soon as and i will upvote you directly
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and...
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and the standard deviation of a list of numbers. Use the function to calculate the average and the standard deviation of the following list of grades : 80 75 91 60 79 89 65 80 95 50 81
Write a user-defined MATLAB function, with two input and two output arguments that determines the height...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height in centimeters (cm) and mass in kilograms (kg)of a person from his height in inches (in.) and weight in pounds (lb). (a) Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. (b) Determine your own height and weight in SI units.
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB function should be voltage across the load (in Vrms, assume 0 phase), frequency Resistance of the load Inductance of the load power factor of the load target power factor The output of the function should be the size of the capacitor that one would need to place in parallel with the load to reach the target power factor. Please submit the code for the...
Convert the following unsigned numbers to the requested form: 01100001 binary to: hex, and also decimal...
Convert the following unsigned numbers to the requested form: 01100001 binary to: hex, and also decimal Hex: Decimal: b) 136 decimal to: hex, and also binary Hex: Binary:
The program will enquiry from the user a name and four decimal numbers: m, a, b...
The program will enquiry from the user a name and four decimal numbers: m, a, b and h. With this information, the program will evaluate moments of inertia (a physical property) for various 3D objects and print them. Use the Scanner class to accept input from the user. Prompt the user for her/his name (i.e. “Ferdinand”). Using her/his name, prompt the user for a value for mass in pounds and save it in a variable (m). Prompt the user for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT