Question

MATLAB

100 90 F 80 70 60 50 40 30 20 10 Notes: After you finish plotting, adjust the axis limits to be as small as possible to contain all data points. Round the final area output to two decimal places. Use ceil() and floor() when determining where to plot the lowest and highest stars in each vertical line, respectively. You are guaranteed that the two inputs will have the same domain; one set of points will not extend past the other. The smallest and largest x-values will be integers, so you do not need to worry about rounding these values when plotting the magenta stars. Hints: When finding which y values to plot at each x value, think about how can you use the colon operator?

Test Cases:

% [area1] = integrals(int1, int2)

int1 =

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40

int2 =

Columns 1 through 14

1 2 3 4 5 6 7 8 9 10 11 12 13 14
3 6 9 12 15 18 21 24 27 30 33 36 39 42

Columns 15 through 20

15 16 17 18 19 20
45 48 51 54 57 60

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

Matlab function:

============

function [area] = integrals(int1, int2)
I1=(1/2)*(int1(2,1)+int1(2,end)+2*sum(int1(2,2:end-1))); % trapezoidal integration
I2=(1/2)*(int2(2,1)+int2(2,end)+2*sum(int2(2,2:end-1)));
area=round(abs(I1-I2),2); % area between two curves rounded upto two decimal places
if I2<I1
dumm=int1; % swap arrays if I2<I1
int1=int2;
int2=dumm;
end
hold on
plot(int1(1,:),int1(2,:),'r') % plotting curves
plot(int2(1,:),int2(2,:),'g')
for i=1:length(int1)
x=int1(2,i):int2(2,i);
plot(int1(1,i)*ones(1,length(x)),x,'m*') % filling area with stars
end
hold off
end

=============

Output:

G: Program Files MATLAB R2017a Editor- GAProgram Files MATLABR2017alintegrals.m Command Window integrals.mtra >> integrals (i

Add a comment
Know the answer?
Add Answer to:
MATLAB Test Cases: % [area1] = integrals(int1, int2) int1 = 1 2 3 4 5 6...
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
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