Matlab problem: How to calculate a rough, approximate, derivative vector by using the following formula?
Afficher commentaires plus anciens
Here is the complete task which I need to solve:
We know that the derivative is the coefficient k of a tangent line with mathematical expression, y=kx + m, that goes through a certain point, P, on a function curve. Lets start with a simple function, namely, y=x^2.
(a) Calculate and Plot this function for -10 < x < 10 with small enough step length to get a smooth curve.
(b) Now, In (a) you calculated two equally long vectors, one for the chosen x values and one with the calculated y values. From these two vectors, we can calculate a rough, approximate, derivative vector that we can call Yprimenum: Use a for-loop to calculate each element of Yprimenum according to the formula:
Yprimenum(i) = (y(i+1) – y(i)) / ∆x Where ∆x is the x step length, or equivallently x(i) – x(i-1)
NOTE: (a) is solved and for the (b) I wrote the following code but not working.
if true
x=-10:10;
for i=1: length(x);
for y=x.^2
Yprimenum=(y(i+1)-y(i))./(x(i)-x(i-1));
end;
end;
display Yprimenum;
end
3 commentaires
Star Strider
le 27 Mai 2014
And ‘not working’ means ... ?
John D'Errico
le 27 Mai 2014
Why do you think it necessary to add the "if true" conditional around your code? Silly.
Jabir Al Fatah
le 30 Mai 2014
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Resampling Techniques dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!