Help Plotting Polynomial and Annotating With Data

3 次查看(过去 30 天)
Im trying to plot a polynomial function (Non Linear) against an ideal straight line (Linear).
I have managed this with my limited MatLab skills, however i would like to extrapolate some data from the graph which i know can be done as i have done it in the past but cannot work out how to do it again.
I want to determine the maximum non linearity between the two plots and illustrate this on the plot
Below is the code i have so far:
y_1=@(x)+1+2*x+0.05*x.^2-0.00833*x.^3;
x_1=0:6;
figure % new figure window
plot(x_1,y_1(x_1),'--b*')
hold on
x2=0:6;
y2=1+2*x2
plot(x2,y2,'r')
hold off
title('Graph of Sensor Non Linearity')
xlabel('Input Units (I)') % x-axis label
ylabel('Output') % y-axis label
legend('Non Linearity','Ideal Straight Line (ISL)','Location','southeast')
grid on
grid minor
Any help is appreciated

回答(1 个)

Star Strider
Star Strider 2015-1-2
How do you define ‘maximum non linearity’?
It would seem to me that it would be defined by the square and cubic terms:
d = 0.05*x.^2-0.00833*x.^3
so you might simply determine the maximum of that expression. Taking the derivative and solving it:
0 = 0.1*x - 0.02499*x^2
gives me a value of x=4.002. The value of d is then 0.26688.
Is that what you want?
  4 个评论
Matthew
Matthew 2015-1-10
编辑:Matthew 2015-1-10
Sorry for my absence i have been distracted by work
Apologies for my vagueness and thankyou for your help and perseverance so far.
It is the maximum deviation vertically that is required.
As a bit of background, the X axis is an input scale and the Y axis is an output, so at input X=1 my linear plot shows an ideal output response (it is a sensor) and my poly shows an actual output response at an input of 1.
I would like matlab to tell me at what input i have my max deviation and what my max deviation value is across an input range of 0-6 but most importantly id like to illustrate this on the plot it produces.
My calculations have determined the max deviation to be at an input of 4 which supports yours.
Yes i can see your argument for pencil and paper and i am using Matlab for verification of the mathematical solution but primarily i chose to use it to provide me with the graph rather than plot it by hand, as i will no doubt be plotting similar problems throughout my studies i figured if i could get the code constructed for the first problem it would speed up the process considerably for the rest.
Could you help with the code for the Plotting and displaying of the max deviation ???
Star Strider
Star Strider 2015-1-10
If you want to plot it, all you need to do is to add a plot call:
y_1=@(x)+1+2*x+0.05*x.^2-0.00833*x.^3;
y_2 = @(x) 1 + 2.* x;
x = linspace(0,6);
dy = @(x) y_1(x) - y_2(x);
figure(1)
plot(x, dy(x))
grid
xlabel('X')
ylabel('Deviation')
The calculated value ‘dy’ should be the ‘maximum vertical distance’, since the difference ‘dy’ is evaluated at the same values of ‘x’ for both ‘y_1’ and ‘y_2’. The analytic solution (that may differ slightly) will take the maximum of the difference in the two curves, first subtracting one from the other and then doing the evaluation, yielding the maximum absolute distance. The difference is whether you do the subtraction after evaluating the two functions (numeric) or before (analytic).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by