Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

complete the matlab code thank you close all; clear; clc; set(groot,'defaultAxesTickLabelInterpreter','latex'); set(groot,'defaulttextinterpreter','latex'); set(groot,'defaultLegendInterpreter','latex'); % domain x = -5:0.01:5; % true function f_true = ; figure(1)

complete the matlab code thank you

image text in transcribed

close all; clear; clc; set(groot,'defaultAxesTickLabelInterpreter','latex'); set(groot,'defaulttextinterpreter','latex'); set(groot,'defaultLegendInterpreter','latex'); % domain x = -5:0.01:5; % true function f_true = ; figure(1) plot(x,f_true,'-k','LineWidth',3) hold on color_cell = {'--r','--g','--b'}; for k=2:4 n = (0:k-1)'; % approximate function f_approx(:,k-1) = ; plot(x,f_approx(:,k-1),color_cell{k-1},'LineWidth',3) hold on end set(gca,'FontSize',30) legend('$f_{ m{true}}(x)$','$f_{ m{approx}}(x,2)$',... '$f_{ m{approx}}(x,3)$','$f_{ m{aaprox}}(x,4)$',... 'FontSize',30,'Interpreter','latex')

Consider n=0(3n)!x3n, that is, the power series obtained by keeping every third term in the Taylor expansion of exp(x). This power series corresponds to the true function ftrue(x)=31(exp(x)+2exp(x/2)cos(23x)). For any positive integer k, define the k term power series approximation fapprox(x,k):=n=0k1(3n)!x3n. Submit a MATLAB code (.m file) named YourlastnameYourfirstnameHW2p2.m that plots 2D line plots for the functions ftrue(x) (in black solid line) versus x[5,5] (in the horizontal axis). In the same figure window, plot fapprox(x,k) for k=2 (in red dashed line), k=3 (in green dashed line), k=4 (in blue dashed line). We shared a starter code YourlastnameY ourfirstnameHW2p2.m inside the CANVAS File section folder: HW Problems and Solutions. You only need to complete lines 11 and 20 in that starter code, then rename the file appropriately with your first and last names. Hint: Look up sqrt, exp, cos, sum, factorial, and power (.) in MATLAB documentation. Also, intuition suggests that as k increases, fapprox should get close to ftrue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions