Question

q1/Find the average temperature in Jeddah weekly period (Use FOR loop. Do not use sum and...

q1/Find the average temperature in Jeddah weekly period (Use FOR loop. Do not use sum and mean built in functions). A = [28 35 36 30 38 32 38]

q2/Use if condition to graph the relation y=f(x) where.(Use for, if and plot)

y= x+2x   0<= x <=3

y= 4x+2   4<= x <8

y= x^2 - 4 8< x <13

MATLAB

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

1. To find the average temperature in Jeddah, we execute the following commands in MATLAB -

A = [28 35 36 30 38 32 38];

% Initialize
Sum = 0;

% For Loop
for k = 1 : length(A);
fprintf('Element %d is: %0.1f \n', k, A(k));
% Accumulate the sum
Sum = Sum + A(k);
% Compute the running mean and print out.
fprintf('After element #%d, the sum = %.1f, and the mean = %.3f\n\n',...
    k, Sum, Sum/k);
end

This gives the average temperature as 33.857.

2. To plot the given conditional function, we execute the following commands -

x = 0:13;
for x=0:13
if x<4
     y(x+1) = x + 2*x;
elseif x>=4 && x<8
     y(x+1) = 4*x + 2;
else % convers the remaning possible x
     y(x+1)= x^2 - 4;
end
end
x = 0:13;
plot(x,y);
xlabel('x');
ylabel('f(x)');

We obtain the following plot -

2468 1024

*Please give a positive review. Thank you.*

Add a comment
Know the answer?
Add Answer to:
q1/Find the average temperature in Jeddah weekly period (Use FOR loop. Do not use sum and...
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
ADVERTISEMENT