- ‘O’ could be improved upon as a function name, since you could confuse it with zero (0),
- ‘D = diff(O);’ will leave you one element short, so use the gradient function instead,
- ‘I = int(O);’ will probably try to invoke the Symbolic Math Toolbox integration and will of course fail, so use trapz or cumtrapz instead.
Trouble With Graphing Functions
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello...I am making a basic program that has the original function, the derivative, and the integral. I then am trying to have it graph them all on the same graph but for some reason it's not working. Every time I run the program an error comes up that says:
Error using plot Non-numeric data is not supported in 'Line'
Is this because I have x declared as a variable using syms x? If so, how do I keep x as a variable but still have it graph?
Thank you!
clc
clear
syms x; %Makes x a variable
%Original Function
O = 2*x; %THIS IS THE ONE THAT CAN BE CHANGED
display('Original Function')
pretty(simplify(O)) %Makes it nice
%Find the Derivative of the Original Function
D = diff(O);
display('Derivative')
pretty(simplify(D)) %Makes it nice
%Find the Integral of the Original Function
I = int(O);
display('Integral')
pretty(simplify(I)) %Makes it nice
%Now, to graph them
B = -10:1:10; %Bounds of the graph
plot(B,O,'k--',B,D,'g--',B,I,'r--');
xlabel('x')
ylabel('y')
title('Original, Derivative, Integral')
grid on %Graph Grid on
1 comentario
Star Strider
el 20 de Mayo de 2016
A few observations:
Respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!