Ask MATLAB Expert

Problem 1 - Write a Matlab script that evaluates the following piecewise function for any user inputs x1 and x2.

2493_figure.png

Test you code using the following values: f(-2, 3) = 7, f (2, -3) = 10, f(2, 3) = 11, f (-2, -3) = 13.

Problem 2 - Prepare a Matlab code to calculates the function

y(x) = In 1/(x2-25)

for any legal user-input x. If the inserted value of x is illegal, report that to the user by printing an error message on the Matlab command window. Note that in the above equation, In is the natural algorithm to the base e, the Matlab function for this mathematical function is log.

Problem 3 - Write a script file that creates a plot of the function shown below. Plot the function from x = -2 to x = 4 (use an increment of 0.01 for your x-vector). Label the axes as "X-Axis" and Y-Axis" respectively, and turn the grid on.

Hint: Be sure to use your "." operator!

f(x) = 3.5-0.5x cos(6x)

Problem 4 - An experiment is performed to measure the intensity of a source of light over a distance. The experiment yielded the following data:

Distance (cm)

10

12

14

16

18

20

22

"x" values

Intensity (lux)

950

640

460

340

250

180

140

"y" values

Write a script file that plots both the experimental data above and the theoretical equation shown below.

y = 95000/x2

For the variables:

  • Create a vector containing experimental distance [Use xe as the variable name].
  • Create a vector containing experimental intensity [Use ye as the variable name).
  • Create a vector containing theoretical distance [Use xt as the variable name) - This vector should contain values from x = 10 to x = 22 at an increment of 0.05.
  • Create a vector containing theoretical intensity [Use yt as the variable name). Be sure to use your "." operator.

For the plot:

Plot the experimental data first, using a red dashed line with circle markers. Use a line width of 1.0 pixels and a marker size of 8.0 pixels.

Title the chart as "Light Intensity as a Function of Distance." Label the x-axis "Distance (cm)" and the y-axis "Intensity (lux)."

Plot such that the x-axis is bounded from 8 to 24 and the y-axis is bounded from 0 to 1200. Also, turn the grid on.

Plot the theoretical model data next, using a line width of 1.0 pixels.

Last, create a legend, labeling the data sets "Experimental" and "Theoretical," respectively.

Problem 5 - For the experimental data points below, write a script that will fit two polynomials (a line and a parabola) to see which predicts the data best and p of the results.

X-Values

0.0

0.5

1.0

1.5

2.0

2.5

3.0

3.5

4.0

4.5

5.0

Y-Values

6.00

4.83

3.70

3.15

2.41

1.83

1.49

1.21

0.96

0.73

0.64

For the variables:

  • Create a vector containing experimental X-Values [Use x as the variable name]
  • Create a vector containing experimental Y-Values [Use y as the variable name]
  • Use polyfit( ) to fit a line to the data [Use p1 as the variable name]
  • Use polyval( ) to compute corresponding y-values for x [Use y1 as the variable name]
  • Use polyfit( ) to fit a parabola to the data [Use p2 as the variable name]
  • Use polyval( ) to compute corresponding y-values for x (Use y2 as the variable name]

For the plot:

  • Plot the experimental data first, using circle markers only and no other formatting. To do this, just specify ' o
  • Label the axes as "X-Axis" and Y-Axis" respectively, and turn the grid on."
  • Note that you don't need to use the hold command. Instead, just plot all of the data sets with a single plot ( ) command.

Finally, using the more accurate polynomial, use polyval ( ) to determine the predicted value at x = 4.25. Assign this to variable c at the end of your script.

Please do it and explain how you did it?

MATLAB, Engineering

  • Category:- MATLAB
  • Reference No.:- M92769807

Have any Question?


Related Questions in MATLAB

Assignment - matlab programmingusing appropriate matlab

Assignment - MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

Assignment details -need to write a code for connecting

Assignment Details - Need to write a code for connecting segments (Lines) a special case of TSP. The problem is to connect lines in 2d/ 3d space with path obstructions. Can you help me write the code for this? Hope you m ...

Assignment -we have daily gridded rainfall data of 40 years

Assignment - We have daily gridded rainfall data of 40 years and structure of the dataset is like below; Lat = [6.5:0.25:38.5]; Lon = [66.5:0.25:100]; Rainfall (135x129x365x40) (Lon, Lat, days, years). Now, we looking fo ...

Question a safe prime is a prime number that can be written

Question : A safe prime is a prime number that can be written in the form 2p + 1 where p is also a prime number. Write a MATLAB script file that finds and displays all safe primes between 1 and 1000.

Question - verify the attached paper with matlab and get

Question - Verify the attached paper with matlab and get all the results in the paper and explain step by step the matlab code. Paper - Improving Massive MIMO Belief Propagation Detector with Deep Neural Network. Attachm ...

Assignment -data is given on which want to do computational

Assignment - Data is given on which want to do computational production planning using Metaheuristic MATLAB Programming: 1) Ant Colony Algorithm on both Partial and Total Flexible Problem. 2) Bee Algorithm on both Partia ...

What comparison of means test was used to answer the

What comparison of means test was used to answer the question

Question 1 manipulate spectral imagehyperspectral images

Question 1. Manipulate spectral image Hyperspectral images can be seen as a generalisation of normal colour images such as RGB images. In a normal RGB colour image, there are 3 channels, i.e. channels for red colour, gre ...

Assignment -matlab codes and simulated model in

Assignment - Matlab codes and simulated model in simulink/matlab and truetime. 1. Matlab codes and simulink model for pid controller optimization using particle swarm optimization (PSO) my plant is integer order 1000/(s^ ...

Assignment matlab programmingusing appropriate matlab

Assignment: MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As