Question

In: Computer Science

Write a MATLAB function named myaccel that accepts three inputs and has a single output. Inputs:...

Write a MATLAB function named myaccel that accepts three inputs and has a single output.

Inputs:

  1. a list of time values
  2. a list of position values
  3. a single time value.

Output:

  1. a single number which is obtained by numerically differentiating position with respect to time twice (forward difference method) and then interpolating the results based on the third input.

Example:

time=0:10;
position=time.^3;
myaccel(time,position,2.8) % should return 22.8 

Solutions

Expert Solution

Fucntion Code

function y = myaccel(time,pos,tq)
pval = pos(time);
h = time(2)-time(1);
y2 = zeros(1,length(time));
for i=1:length(time)-2
y2(1,i) = (pval(i+2)-2*pval(i+1) + pval(i))/h^2; %Formula for forward difference second order
end
y = interp1(time,y2,tq); %interpolation function
end

=============================

Script code to call above function

syms time
position = matlabFunction(time.^3); %Position function defined
time = 0:10;
y = myaccel(time,position,2.8)

=================================

Results

========================================


Related Solutions

Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval...
Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval 0 to 360. function de=equivalent(d) For example, equivalent(540) = 180 equivalent(-30) = 330
Write a function file that accepts each of the four vectors as inputs. The function file...
Write a function file that accepts each of the four vectors as inputs. The function file should plot the data on different graphs in the same window. You need to add axis labels and graph titles. time- 0 5 10 15 20 25 30 A1- 0 7 11 19 15 14 7 A2- 0 10 15 21 16 11 13 A3- 0 9 13 17 22 25 21
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data...
Write a Matlab function called: lin_interp. The function should have three inputs: the two original data arrays (call them x and f), and the array you would like to interpolate to (call it xstar). The function should have one output: the interpolated array ( call it fstar). The function should be able to interpolate x and f onto xstar using linear interpolation and give the result as fstar. The function may not use any intrinsic functions except length.
Write a program that accepts the lengths of three sides of a triangle as inputs. The...
Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle. Recall from the Pythagorean theorem that in a right triangle, the square of one side equals the sum of the squares of the other two sides. Use The triangle is a right triangle. and The triangle is not a right triangle. as your final outputs. An example of the program input...
3. Write a function named "countNonAlpha" that accepts a string. It will return the number of...
3. Write a function named "countNonAlpha" that accepts a string. It will return the number of non-alphabet characters (excluding blanks) in the string. For example, if the string is "Hello, World!", it will return 2 for ',' and '!" in the string. 4. Write a function named "deleteZeros" that takes two arguments: a. an array of integer values; b. an integer for the number of elements in the array; The function will return the number of zeros that it has...
Write a function named mirror_tree that accepts a pointer to the root of a binary tree...
Write a function named mirror_tree that accepts a pointer to the root of a binary tree of integers. Your function should rearrange the nodes into a mirror tree of the original tree. The mirror tree has the left and right subtrees reversed for each node. Constraints: You must implement your function recursively and without using loops. Do not construct any new BST objects in solving this problem (though you may create as many NODE* pointer variables as you like). Do...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should display if the argument "is a multiple of 5" or "is not a multiple of 5".
(IN PYTHON) Write a function that accepts a line of text and a single letter as...
(IN PYTHON) Write a function that accepts a line of text and a single letter as input (case insensitive) and returns the number of times the letter is the last character of a word. Note your program should be able to handle different cases. And check if the user input is a single letter.
Python: Write a function named calc_odd_sum that accepts a positive integer as the argument and returns...
Python: Write a function named calc_odd_sum that accepts a positive integer as the argument and returns the sum of all the odd numbers that are less than or equal to the input number. The function should return 0 if the number is not positive. For example, if 15 is passed as argument to the function, the function should return the result of 1+3+5+7+9+11+13+15. If -10 is passes, it shall return 0. You shall run the program test the result at...
Write a MATLAB function that accepts input vector x and returns the number of local maximums...
Write a MATLAB function that accepts input vector x and returns the number of local maximums of x with value between xmin and xmax. Ask user to input values xmin and xmax at the beginning of the procedure. Use vector x (the vector x from that file consists of 1000 numbers ranging from 0.0044 to 0.67).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT