Question

6. Construct Anonymous Functions to compute the functions below. Use the AFs within a program to find Flx) in the range x (0:0.1.3]. Print the results as a table with columns x, and F(o) f(x)=x3-x-2 for 0 f(x) = x3 _ x _ 1 for 1 1 x 2 f(x) =x3 _ χ for 2.5 x < 3 Construct the anonymous function f(x,y) as shown for the mathematical function below. This function will be used in the future in a program to computes f(x,y) for values of x=[1,10] in steps of 0.5; and for values of y = x2. 7. 10-3ex F(x,y) = sin(y)2

IN MATLAB

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

Please find below the required MATLAB code. I have added comments at suitable places to explain the details. Further, I also plotted the two functions with respect to x values on x-axis to give an understnading of how function f are behaving with two definations.

Note that Q 6. has been solved through part 1 of the code and Q7 through part 2.

Please find below the selectable MATLAB code:

----------------------------------------------------------MAINFILE.M

clear all
clc

%% PART 1
x=[0:0.1:3];

% call function to compute function 1
for k=1:length(x)
result(k,:)=compute_f(x(k));
end
% display result table
fprintf('Result Table 1:\n')   
disp(result)
% plot (x,f(x)) result to see how f(x) changes over x
plot(result(:,1),result(:,2),'r-')
title('Figure 1 using Anonymus Function 1')
clear x result

%% PART 2
% Calling Function 2
x=[1:0.5:10];
% call function to compute function 1
for k=1:length(x)
y=x(k)^2;
result(k,:)=compute_F2(x(k),y);
end
% display result table
fprintf('Result Table 2:\n')
disp(result)
% plot (x,f(x)) result to see how f(x) changes over x
figure
plot(result(:,1),result(:,2))
title('Figure 2 using Anonymus Function 2')

-------------------------------------------------- Function for computing QUESTION 6

function result=compute_f(x)
% Function for part 1

if x>=0 & x<1
f=x^3-x-2; % this f(x) will be used if 0<=x<1
elseif x>=1 & x<2
f=x^3-x-1; % this f(x) will be used if 1<=x<2
elseif x>=2 & x<=3
f=x^3-x; % this f(x) will be used if 2<=x<3
end

result=[x f]; % save result in two columns in form of (x,f(x))
end

-------------------------------------------------FUNCTION FOR QUESTION 7

function result=compute_F2(x,y)
% Function for part 2

F=(10^(-3)*exp(x))/(sin(y^2)); % Function defination

result=[x F]; % save result in two columns in form of (x,f(x))
end

-------------------------------------------

Note that bothe has been called from the mainfile.m.

------------------------------------- SCREENSHOT OF THE CODES

plotfunct.m compute f.mcompute_F2.m+ clear all clc %% PART 1 x-[0:0.1:31: % call function to compute function 1 | for k=1 : l

plotfunct.m X| compute-f.m compute-F2.m function result-computef(x) 1 - Function for part 1 f=x3-x-2; % this f(x) will be us

plotfunct.mx compute fmcompute F2m+ 早function result-compute-F2(x,y) % Function for part 2 F-(10^ (-3) *exp (x)) / (sin (y^2)

----------------------------------------------SAMPLE OUTPUT OF CODE

Command Window Result Table 1 0 2.0000 0.10002.0990 0.20002.1920 0.3000-2.2730 0.4000 -2.3360 0.50002.3750 0.60002.3840 0.700

Command Window 2.6000 14.9760 2.7000 16.9830 2.8000 19.1520 2.9000 21.4890 3.0000 24.0000 Result Table 2: 1.0000 0.0032 1.500

-------------------------------------------PLOT OF TWO FUNCTIONS For visual understanding of output

Figure 1 using Anonymus Function 1 25 20 15 10H 5ト -5 0.5 1.5 2.5

Figure 2 using Anonymus Function 2 20 10 0 10 20 -30 -50 -60 70 -80 10

Add a comment
Know the answer?
Add Answer to:
IN MATLAB 6. Construct Anonymous Functions to compute the functions below. Use the AFs within a...
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
  • Using MATLAB functions, write a program to answer the question 2) [6 pts] Consider the polynomial...

    Using MATLAB functions, write a program to answer the question 2) [6 pts] Consider the polynomial y x3-8x2 + 19x - 12 a) Create an anonymous function for y and use that for parts (b)-(d) b) Plot the function over the range 0 s x s 5. Use fplot. c) Find all zeros of the function d) Find the minimum point

  • Please help me with this matlab problem, the answer should look like the picture below. Thank...

    Please help me with this matlab problem, the answer should look like the picture below. Thank you %1 Write an anonymous function that will receive data in the form of a plot function handle, x and y vectors, and a handle to a plot function and wil1 produce the plot. For example, a call to the function would look like the following: myPlot (@bar,x,y). x -pǐ : 0.25 : pi; y sin(x); % Piave you anonymous funcyion code here subplot...

  • For the following functions and using Boolean identities a) Simplify the given functions b) Construct the...

    For the following functions and using Boolean identities a) Simplify the given functions b) Construct the truth table for both of them showing the output of the original function and the simplified one and compare the two outputs? c) Draw the logic circuits for both the original function and the simplified one? 1. FIX, Y, Z) = X'+Y' + XY'Z 2. F(X, Y, Z) = (X+Y)(X' +Y+Z)

  • photo of the code please and an explnation if possible, Construct a simple MATLAB function program...

    photo of the code please and an explnation if possible, Construct a simple MATLAB function program my_factorial which calculates product of first n positive integer numbers (i.e. find factorial n!). For full points: - Make sure you protect the code from illogical use (n must be positive integer) - Test the function by comparing with built in MATLAB function factorial(n) - Make sure you test your function for any limitations. O marks) -3. Using my factorial function from the previous...

  • 1. Complete the table below for f(x)=3". Use exact values. No work needed. [1.25 points) -...

    1. Complete the table below for f(x)=3". Use exact values. No work needed. [1.25 points) - 101 y = f(x) 2. Consider the functions gtx)=(13)" and h(x) =--() +4 12.5,1.25, 1.5 points) a) The points given below (in the first column) belong to g(x)= - Perform two b) Use the point found in part a) to sketch a graph of y=h(x). Include the horizontal asymptote as a dashed line. Approximate point placement where necessary. transformations (and show how the points...

  • Design and construct a computer program in Java. The following is a plot of the function...

    Design and construct a computer program in Java. The following is a plot of the function f(x) = sin(x3) + x2 : In order to illustrate the effects of the two major error sources, rounding and truncation, attempt to determine an approximation to the derivative of f(x) at x = 2.0 radians using the difference approximation given below. (The true answer is 4 + 12 cos(8) or about 2.2539995942966376896). Use the formula: f'(x) ≃ (f(x+h) - f(x)) / h with...

  • (1 point) Compare and discuss the long-run behaviors of the functions below. In each blank, enter...

    (1 point) Compare and discuss the long-run behaviors of the functions below. In each blank, enter either the constant or the polynomial that the rational function behaves like as x + Foo: 23 – 3 1. x4 – 3 f(x) = ar — x2 – 3 23 – 8 , and h(x) = 23 – 8' x3 – 8' f(x) will behave like the function y = as x + +0. help (formulas) g(x) will behave like the function y...

  • Model 1: Solving fory Most of the functions we have seen in this course are like those in Table 1 (and the first three...

    Model 1: Solving fory Most of the functions we have seen in this course are like those in Table 1 (and the first three functions in Table 2): They can be written explicitly in terms of x. That is, the function can be written as a single equation in the form y-... or, alternatively, f(x)-... in terms of x only Table 1 Table 2 Same function solved for vin terms of x only y=2x + 4 y=x3-3x2 + 13x-7 18x+5y...

  • Compute Laplace transforms of the following functions: (a) f1 = (1 + t) (b) f2 =...

    Compute Laplace transforms of the following functions: (a) f1 = (1 + t) (b) f2 = eat sin(bt) 11, 0<t<1, (c) f3 = -1 1<t<2, | 2, t>2, Find the functions from their Laplace transforms: (a) Lyı] s(s + 1) (s +3) 2+s (b) L[42] = 52 + 2 s +5 (c) L[y3] = Solve the following initial value problems using the Laplace transform. Confirm each solution with a Matlab plot showing the function on the interval 0 <t<5. (a)...

  • Use Heun's Method please! Must use MATLAB and please use ANONYMOUS function. WIll rate answer 5 stars if done corre...

    Use Heun's Method please! Must use MATLAB and please use ANONYMOUS function. WIll rate answer 5 stars if done correctly. Use Heun's method (RK2), choose a step size Perform the same computation as in Prob. 28.19, but rather than using a constant wind force, employ a force that varies with height according to: 200z -2:/30 f(2) 5+z Problem 28.19 The following equation can be used to model the deflection of a sailboat mast subject to a wind force: d2 (L-z)...

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