Question
(MatLab Plot the function A*sin(x) + 2(x 2 ) (x = 0 to 5) for 5 values of A. Then, create a legend with string
(MatLab
Plot the function A*sin(x) + 2(x2) (x = 0 to 5) for 5 values of A. Then, create a legend with string functions. To get the extra credit, an anonymous function and for loop must be used.
Step by Step Instructions:
The goal of the problem will be to create individual strings for each needed legend entry and store the entries into a cell array, before finally calling legend.
To start, define A = [1,3,5,7,9]
Define your function anonymously (Depending on where you place it in your code, youll need to make your function have 1 or 2 local variables (either @(x) or @(a,x)))
Plot the function in a for loop while varying the appropriate variable
Define the legend entry for the loop by stating, as a string, what A equals for the line being plotted. Store into a cell array
Consider how the previous point should be done. What can be kept the same? What needs to be different? Look up (if you dont already understand) commands like strcat or sprint. The command num2str should also help
After the for loop, call the legend command with the cell array of legend entries. Move the legend so it doesnt sit on the graph
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started