188k views
3 votes
From the given data t and tempF, answer the followings.

- Create a row vector tq with elements starting at 0 hour and ending at 24 hours with increments of 6 minutes ( 0.1 hour)
- Compute a interpolated temporature for the vector tq, assign the result to the variable tempFq. (use the interp1 function with spline method)
- Plot the result (tq vs temp q ) with the input ( t, temp )
- Find the maximum temperature ant its time, and assign the result on tempFmax and tmax. (use min function)
- Find the minimum temperature ant its time, and assign the result on tempFmin and tmin. (use max function)

MATLAB
t=0:3:24; 2
tempF =[42,40,39,44,53,56,51,45,43];
plot(t, tempF, 'o' );
xlabel ((′Hr)′)′);
ylabel( 'Temperature (F)′);
box off; grid on;
% your code here

User Varius
by
8.2k points

1 Answer

3 votes
Here is the code to perform the tasks mentioned:

```MATLAB
t = 0:3:24;
tempF = [42,40,39,44,53,56,51,45,43];

% Create a row vector tq with elements starting at 0 hour and ending at 24 hours with increments of 6 minutes (0.1 hour)
tq = 0:0.1:24;

% Compute interpolated temperature for the vector tq using the interp1 function with spline method
tempFq = interp1(t, tempF, tq, 'spline');

% Plot the result (tq vs tempFq) with the input (t, tempF)
plot(t, tempF, 'o');
hold on;
plot(tq, tempFq);
xlabel('Hr');
ylabel('Temperature (F)');
box off;
grid on;

% Find the maximum temperature and its time
[tempFmax, idx_max] = max(tempF);
tmax = t(idx_max);

% Find the minimum temperature and its time
[tempFmin, idx_min] = min(tempF);
tmin = t(idx_min);
```

Note: Make sure to run the code after defining the variables `t` and `tempF` as given in the question.
User Mranders
by
8.0k points