1
   

Matlab Second Diff Plotting Problem

 
 
el pohl
 
Reply Sun 5 Dec, 2004 11:48 pm
Hope this is the correct section to post this...

Im working on a Matlab program. I have to calculate the second derivative of a given equation. The problem is that plotting the derivative is necessary, and that's where I'm stuck.

Here's what I've got so far:

% Evaluar f(x) y f'(x) usando diferencias hacia atras.
%
x = -10:0.1:10;
f = x.^3 - 5*x.^2 + 2*x + 8;
df = diff(f);
dx = diff(x);
df_dx = df./dx;
xd = x(2:length(x));
d2f = diff(f,2);
d2x = diff(f,2);
d2f_d2x = d2f./d2x;
%
% Graficar lo anterior.
%
subplot(2,1,1),...
plot(x,f,xd,df_dx,xd,d2f_d2x),...
title('Derivada de un polinomio de quinto grado'),...
xlabel('x'),grid,...
ylabel('f(x)'),...
axis([-4,5,-500,1500]);

On the internet I found out that diff(f,2) would calculate the second diff, I guess thats true. Ignore the text in spanish Razz.

When I try to run the program, the following appears:

??? Error using ==> plot
Vectors must be the same lengths.

Error in ==> C:\MATLAB6p5\work\segunda_diferencial.m
On line 16 ==> plot(x,f,xd,df_dx,xd,d2f_d2x),...

Hope you can help.

Thanks!
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 644 • Replies: 1
No top replies

 
el pohl
 
  1  
Reply Mon 6 Dec, 2004 08:41 pm
Allright! I got it! Thanks though!
0 Replies
 
 

Related Topics

Evolution 101 - Discussion by gungasnake
Typing Equations on a PC - Discussion by Brandon9000
The Future of Artificial Intelligence - Discussion by Brandon9000
The well known Mind vs Brain. - Discussion by crayon851
Scientists Offer Proof of 'Dark Matter' - Discussion by oralloy
Blue Saturn - Discussion by oralloy
Bald Eagle-DDT Myth Still Flying High - Discussion by gungasnake
DDT: A Weapon of Mass Survival - Discussion by gungasnake
 
  1. Forums
  2. » Matlab Second Diff Plotting Problem
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 05/04/2024 at 03:52:14