Problem 6. Basies Part 2 (1 point. Instructor\'s Initials Derivatives, version 1
ID: 3198707 • Letter: P
Question
Problem 6. Basies Part 2 (1 point. Instructor's Initials Derivatives, version 1. Suppose you have a function y-x+x. You know at a glance that dy/dx - 2x +1, right? To find the derivative using Matlab, Letx [0:.01:3] and y-x.2+x. Then compute the derivative using dydx diff(v)/diff(x) (Make sure you understand what the diff function does). Notice that x has 301 elements with a spacing of 0.01. Create a new x vector of points between the original x points with x2 x(1:300)+.005. Finally, convince yourself that you've created the derivative by plotting both the original function and the derivative: plot(x,y, x2,dydx). Derivatives, version 2. Same problem as before: y xx. Let x (0:.01:3] and y x.A2+ x. This time use the gra gradient generates a vector with the same number of points as y, so you can directly plotd function of x as follows: plot?x, y, x, dydx Ver2). In general, gradient is easier to use than diff(y)/diffix). It only works if x is uniformly spaced, and it works best if x is densely spaced. This will probably be discussed in the lecture. dient function: dydxVer2-gradient(y,01). where does the .01 come from? Notice that ydxVer2 as a Numerical Integration. Matlab only does definite integrals, unless you buy the symboltc toolbox. This means that Matlab can compute S" sin(x) dx, but not f sin(x)dx. We already know that " sin(x)d)2. Now compute it using Matlab. Start with a function handle as follows: f-a(x) sin(x). Then integrate using a integral(f,0,pi). Numerical Integration practice. Determine eI-sin(x)dx. Remember that for Matlab, infinity is given by inf. So your integral will go from 0 to inf. IExplanation / Answer
%Derivatives, version 1
x=[0:0.01:3];
y=x.^2+x;
% diff(x) calculates differences between adjacent elements of x
dydx=diff(y)./diff(x);
x2=x(1:300)+.005;
plot(x,y,x2,dydx)
%Derivatives version 2
x=[0:0.01:3];
y=x.^2+x;
dydxVer2=gradient(y,.01);
%.01 comes from the space between the points in x
plot(x,y,x,dydxVer2)
%Numerical integration
f=@(x)sin(x);
a=integral(f,0,pi);
%disp is for showing the result
disp(a)
%Numerical integration practice
% g=@(x)(exp(-x)).*((1-sin(x)).^(1/2));
g=@(x)(exp(-x)).*sqrt(1-sin(x));
I=integral(g,0,inf);
disp(I)
%The integral is 0.6356
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.