Question

in matlab

Write and test a function double(x) which doubles its input argument, i.e., the statement x-double (x) should double the value in x.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code :

function x= double(x) //function name is double and input parameter is x and output variable name is also x
x=x+x; stroing added value to x
end

function calling:

val=2.0 //creating variable val
double(val) and caling double function with this value as parameter

output:

ans=4.0

the compilation and execution will happen eventhough input variable name and output variable name is same:

e Computer Sc x-A Declare funct × / く/> Online Octeve ×く◆ MATLAB Func × \く/> Online Octeve × . Var able name × KCSecure https

Add a comment
Know the answer?
Add Answer to:
in matlab Write and test a function double(x) which doubles its input argument, i.e., the statement...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument,...

    Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc. NOTE: A prime number is a...

  • 3. Write a function that receives an input argument x and returns y and z, which...

    3. Write a function that receives an input argument x and returns y and z, which should be calculated as follows

  • b) (2.5 marks) Write a Matlab user defined function that takes the letter grades (i.e. AABBC) as input and returns...

    b) (2.5 marks) Write a Matlab user defined function that takes the letter grades (i.e. AABBC) as input and returns if the student entitled to the honor list or not. The student is considered in the honor s f he or she satisfies the following three conditions: a. An average GPA of 3.5 and above and b. At least two classes with A mark and e. no class with a mark less than C (i.e. no D or F) The...

  • Using matlab Write a function that receives a vector as an input argument and prints the...

    Using matlab Write a function that receives a vector as an input argument and prints the individual elements from the vector in a sentence format. One example of calling this function on the command window looks like >>printvec([1.12 23 9.245]) Element 1 is 1.12 Element 2 is 23.00 Element 3 is 9.25 1. (Note: your function should work for any vector.)

  • First Derivative Central: Write a user written function that expects as its input argument a vector...

    First Derivative Central: Write a user written function that expects as its input argument a vector of x values and a vector of corresponding y-values. The function must return a matrix with 2 columns. The first column contains ‘mid-point’ x-values. The second column must contain the centered difference approximations for the first derivative, dy/dx, at the step midpoints. In other words, the x values [(x2+ x1) / 2 , (x3+ x2) / 2,..., (xn+ xn-1) / 2] and corresponding first...

  • How will the function look in MATLAB? Write a function called plot_prop that takes an input...

    How will the function look in MATLAB? Write a function called plot_prop that takes an input value n. You need to plot a parabola i.e. a plot which ranges from a value to zero and then again from zero back to that value. Your parabola must be able to take any number (n) as an input. a) The line of the parabola is magenta and a solid line. b) The points of the parabola are starred. c) The X-axis is...

  • Write a Matlab function that argument of the function that represents the sam function that plots...

    Write a Matlab function that argument of the function that represents the sam function that plots the following signal for O<t<700Ts (where Ts is the " that represents the sampling frequency) x(t) = 2n=-50 4k,sinc(t - nt's) where kn ( 1 if n = 0 Note: sinc(x)=sin(nx)/(xx) of n0

  • Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr,...

    Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr, a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. As a second output argument called mmm, it provides the difference between the maximum and minimum element in the entire matrix. See the code below for an example: >> A = randi(100,3,4) A = 66 94 75 18 4 68 40 71 85 76...

  • i need this done in Matlab 8. Write a function which reverses a vector, i.e. if...

    i need this done in Matlab 8. Write a function which reverses a vector, i.e. if the input is (4, 2, 1,5,-3], the output would be [-3,5, 1, 2,4]. 9. Write a function which computes the sum of every second element in a vector.

  • 7. #4. 18 Following is a recursive function which takes as input (argument) a vector $x$...

    7. #4. 18 Following is a recursive function which takes as input (argument) a vector $x$ and returns a scalar. Either by looking carefully at the function, or by running the function with a few simple input vectors and observing the returned values in each case, determine what the function is doing. 29 00- "**{r} 01 - myfun=function(x){ 02 - if(length(x)=-1){return(x) C03 - } else 84 return(x[1]+my funcx[-1])) 205 - ) 206 myfun(c(1:1000)) #here's what happens when it is applied...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT