1 / 4

Problems and solutions Session 4

Problems and solutions Session 4. Problems. Implement the minimum search of previous examples (Way 1-4). Write the previous ode –example as an anonymous function handle call. Compute the integral ∫ [0,1] F(x) dx, F(x) = sqrt(x)/exp(x^2), with quad. Problems – my function function.

tanaya
Download Presentation

Problems and solutions Session 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Problems and solutionsSession 4

  2. Problems • Implement the minimum search of previous examples (Way 1-4). • Write the previous ode –example as an anonymous function handle call. • Compute the integral ∫[0,1] F(x) dx, F(x) = sqrt(x)/exp(x^2), with quad. Introduction to MATLAB - Solutions 4

  3. Problems – my function function • Write a function differf.m that computes the differential of the argument function f:RnRm at a given point: function df = differf(fff,x,h) Here, fff is the function argument x is the point in Rn at which the differential is computed h is the small number in the difference quotience Recall, a differential at x is a linear matrix Df(x) with f(x+h) = f(x) + Df(x)h + error(x,h), and the j’th column of Df(x) can be computed as Df(x)(:,j) = lim (f(x+hej)-f(x))/h. Test your differf with a) f(x) = x^2+3x, b) f(x) = Ax, A = rand(4,5). Introduction to MATLAB - Solutions 4

  4. [t,y] = ode23(@(t,y) [y(2);y(2)+y(1)],[0,1],[0;1]); integral = quad(@(x) sqrt(x)./exp(x.^2),0,1); function df = differf(fff,x,h) n = length(x); % dimension of the starting space fx = fff(x); % value at x – computed only once! m = length(fx); % dimension of the goal space df = zeros(m,n); % reserve the memory space for df for j = 1:n ej = zeros(n,1); ej(j) = 1; df(:,j) = (fff(x+h*ej)-fx)/h; end CALL differf(@(x) x.^2+3*x,1,0.0001) % derivative at x=1 A = randn(4,5) dA = differf(@(x) A*x, ones(5,1), 0.0001) % derivative at x=ones(5,1) % dA should be A !! Some solutions Introduction to MATLAB - Solutions 4

More Related