Question

Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to...

Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to symbolically compute the derivative of ln(x) on the interval from -5 to 5, containing 100 data points. Your script file should output a plot of the derivative of ln(x) (taken from your function) vs x. Use a line with circular markers for the plot and include a grid and appropriate labels.

The user-defined function should

1. Receive a single x value as input.

2. Symbolically take the derivative of the mathematical function log(x).

3. Substitute the particular x value into the derivative.

4. Return the computed derivative back to the script file to be stored in a vector.

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

function dx = d_log(x)
    dx = 1./x;
end

vec = linspace(-5,5); %generate 100 numbers

results = d_log(vec); %1st result
figure
plot (vec,results,'b--o')) %plot the graph

I hope this helps you....

Add a comment
Know the answer?
Add Answer to:
Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to...
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
  • Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following...

    Question 1: Creating a user-defined function Write a user-defined MATLAB function named PBTask4pl_f.m for the following math function with x the input argument and y the output y(x)=0.8x4-13x2-5x The function should work for x being a scalar or a vector. Write a script file named PBTask4pl.m to a) Use the function to calculate y(3) and y(5) and display the results in command window b) Use the function to make a plot of the function y(x) for -5:5: x 5:5. Label...

  • Solve in Matlab by using Script file: Problem 4: Write a user-defined MATLAB unction that calculates...

    Solve in Matlab by using Script file: Problem 4: Write a user-defined MATLAB unction that calculates the determinant of a 3x3 matrix by using the formula: A22 A23 11 A32 A33 A23 A12 A31 A33 21 A For the function name and arguments use d3-det3by3 (A), where the input argument A is the matrix and the output argument d3 is the value of the determinant. Write the code of det3by3 such that it has a subfunction that calculates the 2x2...

  • using matlab 3. Write a script that will read the ages vector.dat file created in the...

    using matlab 3. Write a script that will read the ages vector.dat file created in the previous problem. - the script will print the number of persons in the group - the script will print the maximum and minimum ages in the group - the script will compute and print the "average age" The script should return something like: The file contains the ages of a group of 50 people The maximum and minimum ages in the group are 10...

  • 1. Write a Matlab function, piecewise (), that will calculate and return the value of the...

    1. Write a Matlab function, piecewise (), that will calculate and return the value of the function f(x) defined by: 0<rS3 3<s5 e (x) -cos(3r) 2 sin(r) 2. Write a Matlab script to plot the function f(z) on the interval -3ss8. Ensure the output is sufficiently smooth by declaring z with enough data points. The plot should include the title My Piecewise Function, appropriate axis labels and grid lines. 1. Write a Matlab function, piecewise (), that will calculate and...

  • Function / File Read (USING MATLAB) A) create a user-defined function : [maxsample , maxvalue , numsamples]=writetofile(sname,strgth) to do the following: The user-defined function shall: -Accept as t...

    Function / File Read (USING MATLAB) A) create a user-defined function : [maxsample , maxvalue , numsamples]=writetofile(sname,strgth) to do the following: The user-defined function shall: -Accept as the input a provided string for the sample name (sname) and number for strength (strgth) - open a text file named mytensiledata.txt, with permission to read or append the file. - Make sure to capture any error in opening the file - Write sname and strgth to the file - Close the file...

  • MATLAB, please provide code script Objective: Create a function file that animates projectile motion defined by...

    MATLAB, please provide code script Objective: Create a function file that animates projectile motion defined by the following equations in a subplot. Your function should accept user inputs of launch speed and launch angle. The output of your function will be a top subplot that displays height (y) as a function of x. The bottom subplot should display the vertical velocity while the projectile is in motion. A video of what your animation should look like is posted with this...

  • MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the...

    MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the following math function 3 o-0.47x The input to the function is x and the output is y. Write the function such that x can be an array (use element-by-element operations) (15 pts) Use the function in (a) the command window to calculate y(-2) and y(5) (b) a script file HW7P2.m to determine y(x) for 0.001 Sx S 10 with 1000 points. Hint: Use the...

  • 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.

  • DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the...

    DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the following calculations. Your script will use the functions you create. Label all graphs appropriately. For this project, do not have your homemade functions fprintf anything, instead have all your fprintf commands within your script. Attach your published script file along with .m files for your functions. Exercise 1. A fundamental iterative method for finding the roots of equations of one-variable is known as Newton's...

  • Please use matlab cars. Answer: Function file; Command Window: 5.4 Write a user-defined function that plots...

    Please use matlab cars. Answer: Function file; Command Window: 5.4 Write a user-defined function that plots a circle given the coordinates of the center and the radius. For the function name and arguments use circleplot(x,y,R). The input arguments are the and y coordinates of the center and the radius. Use linspace to generte the angle from 0 to π with 100 points. (Hint: the circle equation: x+Rcos and yy-yRsin 0.) This function has no output arguments. Plot the circle using...

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
ADVERTISEMENT