Question

Write a user-defined MATLAB function for the following math function y(x). The input to the function...

Write a user-defined MATLAB function for the following math function y(x). The input to the function is x and the output is y. y(x)=-(0.2*x^4)+((e^-0.5*x)*x^3)+7*x^2 Call the function to calculate y(x) over the interval -3 ≤ x ≤ 4 for each increment of 1. Display x and corresponding y(x) in a text file with labeled column headings. Use the type command to display the contents in the text file.

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

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

clear all
close all
clc
x=-3:1:4;
y=calculate(x);
fileID = fopen('out.txt','w');
fprintf(fileID,'x\t\ty(x)\n');
for i=1:length(x)
fprintf(fileID,'%d\t%f\n',x(i),y(i));
end
fclose(fileID);
type('out.txt');
function y=calculate(x)
y=-(0.2*x.^4)+((exp(-0.5*x)).*x.^3)+7*x.^2;
end

Kindly revert for any queries

Thanks.

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

clear all
close all
clc
x=-3:1:4;
y=calculate(x);
fileID = fopen('out.txt','w');
fprintf(fileID,'x\t\ty(x)\n');
for i=1:length(x)
fprintf(fileID,'%d\t%f\n',x(i),y(i));
end
fclose(fileID);
type('out.txt');
function y=calculate(x)
y=-(0.2*x.^4)+((exp(-0.5*x)).*x.^3)+7*x.^2;
end

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write a user-defined MATLAB function for the following math function y(x). The input to the function...
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...

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

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

  • 1. in Matlab, write a user-defined function, with two input (r,theta) , θ expressed in degrees)...

    1. in Matlab, write a user-defined function, with two input (r,theta) , θ expressed in degrees) and two output arguments (X,Y). The inputs are a location on a polar coordinates corresponding to Cartesian plane expressed in rectangular coordinates. The picture below describes the problem. X, Y rcos θ Some formula that you may need: x = r * cos (theta * pi/180); y r * sin(theta * pi/180); Test your code for r=7, theta=55° and present your results.

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

  • Please use MatLab and comment code. Problem 2 Write a MATI AB user-defined function y-M?SotxType): x...

    Please use MatLab and comment code. Problem 2 Write a MATI AB user-defined function y-M?SotxType): x is a vector containing numbers. and Type can be 'Ascending' or Descending'. This function should sort the given vector x in the ascending or descending order based on the user's request and return the desired vector as the output. Do not use MATLAB built-in function sort. Hint: When you call this function you need to use for Ascending or Descending since they are strings.

  • Create a function m-file for the following expression which has two inputs X and Y. Call...

    Create a function m-file for the following expression which has two inputs X and Y. Call it “zoom”. Z = eVX2+Y2 /(X + Y) This function (zoom) can be in a separate script or as the last cell in your main m-file (which includes all of your solutions). Use Zoom to generate values for Z for X and Y values varying from 1 to 4 with an increment of 0.2. Also generate a table that includes all values for X...

  • B.1 Write a MATLAB user-defined function for interpolation with linear splines Name the function Yint =...

    B.1 Write a MATLAB user-defined function for interpolation with linear splines Name the function Yint = Linear Splines, y, rint), where the input ar- guments and y are vectors with the coordinates of the data points and rint is the coordinate of the interpolated point. The output argument Yint is the y value of the interpolated point. Also write a program in a script file that plots the data points and the curve of the Linear splines that interpolates the...

  • MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note:...

    MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note: input values are specified in the function call) Output: calculated maximum value Create a row vector A of values from 50 down to 0, with an increment of 0.5 Multiply the elements of A and the square of the elements of the input vector Store the results in B Find the maximum value of B and store it in C – this is the...

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