THE CODE FOR THE ABOVE QUESTION IS :
function main()
sizelbs = [6, 7, 10, 18, 22, 24, 30];
unstuffed = [2.00, 2.50, 3.00, 3.50, 4.00, 4.50, 5.00];
stuffed = [2.25, 2.75, 3.50, 4.50, 5.00, 5.50, 6.25];
% (a)
% plotting the given data
plot(sizelbs, unstuffed);
title('Cooking time for turkeys at 325°C');
hold on
plot(sizelbs, stuffed);
hold on
% (b)
% x will hold 30 points from 7 to 22
x = linspace(7,22,30);
% y1 is the interpolated data for unstuffed turkey
y1 = zeros(1,length(x));
for i = 1:length(x)
y1(i) = LagrangeInterp([7 10 18 22],[2.50 3.00 3.50
4.00],x(i));
end
% plotting the data obtained
plot(x,y1,'--');
hold on
% y2 is the interpolated data for stuffed turkey
y2 = zeros(1,length(x));
for i = 1:length(x)
y2(i) = LagrangeInterp([7 10 18 22],[2.75 3.50 4.50
5.00],x(i));
end
plot(x,y2,'--');
hold on
% (c)
% getting the value from the plotted points the value at x = 15
for
% stuffed and unstuffed turkey
stuffed15lbs = interp1(x,y1,15);
unstuffed15lbs = interp1(x,y2,15);
% plotting the points obtained and printing them also
plot(15,stuffed15lbs,'o');
hold on
plot(15,unstuffed15lbs,'o');
legend('Unstuffed','Stuffed','Unstuffed Interpolated','Stuffed
Interpolated','Recommended cooking time for stuffed turkey
15lbs','Recommended cooking time for unstuffed turkey
15lbs');
xlabel('size (lbs)');
ylabel('time (h)');
hold off
fprintf('The recommended time for 15lbs stuffed and unstuffed
turkey is %fh and %fh
respectively.\n',stuffed15lbs,unstuffed15lbs);
end
function yi = LagrangeInterp(x,y,xi)
n = length(x);
L = zeros(1,n);
for i = 1:n
L(i) = 1;
for j = 1:n
if j ~= i
L(i) = L(i)*(xi-x(j))/(x(i) - x(j));
end
end
end
yi = sum(y.*L);
end
SCREENSHOT OF CODE :
OUTPUT :
please provide matlab solution too 3. Butterball recommends the following cooking times for turkeys at 325...
I need to create a MATLAB function, bvp_solve.m, to approximate the solution y(x). The function takes the number of grid points n as an input. The outputs are grid vector x and the solution vector y %% This is the function i have so far: function [xi, yi] = bvp_solve(n) % BVP_SOLVE computes the solution y(x) of a two-point boundary value problem % using finite difference method (FDM). % The governing equation is % y''' = -y + (x -...
CONVERT THE FOLLOWING MATLAB CODE FROM SOURCE PANEL METHOD TO VORTEX PANEL METHOD: clc;clear all;close all; Vinf=100; % freestream velocity R=1; % cylinder radius n=4; % number of panels alpha=2; % angle of attack dtheta=2*pi/n; theta=pi+pi/n:-dtheta:-pi+pi/n; X=R*cos(theta); Y=R*sin(theta); for i=1:n % angle of flow with tangent of panel phi(i)=-alpha+atan2((Y(i+1)-Y(i)),(X(i+1)-X(i))); % angle of flow with normal of panel beta(i)=phi(i)+pi/2; x_mid(i)=(X(i+1)+X(i))/2; y_mid(i)=(Y(i+1)+Y(i))/2; S(i)=sqrt((Y(i+1)-Y(i))^2+(X(i+1)-X(i))^2); end % Source Panel Method for j=1:n neighbors(:,j)=[1:j-1 j+1:n]; xi=x_mid(j); yi=y_mid(j); for i=1:n-1 m=neighbors(i,j); Xj=X(m); Yj=Y(m); Xj1=X(m+1); Yj1=Y(m+1); A=-(xi-Xj)*cos(phi(m))-(yi-Yj)*sin(phi(m));...
Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials. Download the template for function lagrange interp.m. The tem Plate is in homework 4 folder utl TritonED·TIue function lakes in the data al nodex.xi and yi, as well as the target x value. The function returns the interpolated value y. Here, xi and yi are vectors while x and y are scalars. You are not required to follow the template; you can create the...
Please follow following scripts: Script for part A:Script for Part B: Matlab Exercises 1. Find the determinant (command: det(A)) and the condition number (command: cond(A)) of the Hilbert matrix H of order k (command: hilb(k)), for k = 1,2, ..., 10. Plot the determinant and the condition number as a function of k using a logarithmic scale for the vertical axis. Hint: The template to help you with this homework assignment is homework/hw15.m. 2. Determine if y is in the...
ME 32200 Programming course (MATLAB) 4. Please finish the following Matlab code for solving the ODE: dy = y(1+1) dt I.C. y(0) = 0 with the multi-step 4th order Milne's Method, and apply 4th order Runge Kutta method to the first 4 points (1 boundary point and the next 3 points). (Hint: 4th order Milne's Method Predictor: 7i+ = Y-3 +h(2f;- fi- +25,-2) Corrector: y = y + + +0. +45j + fi-) Where f; = f(t;,y,) and Fit =...
Can you please help me with this question. Much appreciated. So I have a sample code, but we need to change the code in a way that fits the problem. A planar slab of material is initially at a temperature of 300 K. At the time t=0, microwave radiation is directed at the material, leading to internal heat generation that is uniform within the material. The sides of the slab experience negligible heat losses and a water bath maintains the...
Question 1 QUESTION 2 Use the attached Matlab code as a basis to solve the following ordinary differential equation using Euler's method, with timestep of 0.1, from t-0to t-100. d)0) -0 - sin (5vt cos(у Plot y versus t from t=0 to t=100. How many local maxima are on this interval(do not include end points). Be careful to count them all! Answer should be an integer 1 w% Matlab code for the solution of Module 2 3 dt-9.1; %dt is...
Please explain the solution and write clearly for nu, ber 25. Thanks. 25. Approximate the following functions f(x) as a linear combination of the first four Legendre polynomials over the interval [-1,1]: Lo(x) = 1, Li(x) = x, L2(x) = x2-1. L3(x) = x3-3x/5. (a) f(x) = X4 (b) f(x) = k (c) f(x) =-1: x < 0, = 1: x 0 Example 8. Approximating e by Legendre Polynomials Let us use the first four Legendre polynomials Lo(x) 1, Li(x)...
Please provide solution/methods so I can understand how this work. Given a algorithm with f(n) 5n2 + 4n + 14 in the worst case, f(n) 3n2 + 17 log, n + 1in the average case, and f(n) in 17 the best case. Which of the following would be the tightest possible asymptotic descriptions of the algorithm? The following statement that would be tightest possible asymptotic description of the algorithm above A) O(n) B) o (n) C) (n?) D) On Log...
For this project, each part will be in its oun matlab script. You will be uploading a total 3 m files. Be sure to make your variable names descriptive, and add comments regularly to describe what your code is doing and hou your code aligns with the assignment 1 Iterative Methods: Conjugate Gradient In most software applications, row reduction is rarely used to solve a linear system Ar-b instead, an iterative algorithm like the one presented below is used. 1.1...