Problem graphing the % error between a real function and its linearization using contourf in MATLAB
Show older comments
I am trying to visualize the percentage error between a real function and its linearized version in a contour map (contourf). I have defined my reference variables and calculated the relative error as:
Where:
- g = X./Y is the real function.
- z is the linearized function
- Xref = 5, Yref = 4 are the references.
The code I am using is the following:
Xref = 5;
Yref = 4;
[X,Y] = meshgrid(linspace(0,10,50),linspace(3,5,50));
g = X./Y;
z = Xref/Yref+1/Yref*(X-Xref)-Xref/Yref.^2*(Y-Yref);
surf(X,Y,g,"FaceColor","#EDB120","LineStyle","none")
hold on
surf(X,Y,z,"FaceColor","#0072BD","LineStyle","none")
xlim([0 10])
ylim([3 5])
zlim([-0.5 3.5])
box on
legend("g=X/Y","Linearized")
xlabel("X(t)")
ylabel("Y(t)")
zlabel("g=X/Y")
hold off
% Error Graph (%)
Error3 = abs(z-g)./g*100;
contourf(X, Y, Error3)
xlabel("X(t)")
ylabel("Y(t)")
The result I should get would look like this:

I think the problem is the way I'm calculating the %Error between those two functions rather than how I'm using the contourf function, but i don't know.
Accepted Answer
More Answers (0)
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

