Coding to find difference between two lines on a x y plane

32 ビュー (過去 30 日間)
Eddy Ramirez
Eddy Ramirez 2020 年 10 月 18 日
回答済み: Manvi Goel 2020 年 10 月 29 日
is there a way to generate a code on MatLab that will find the difference between two different lines?
For example, I have a straight line (linear) with the following points (-10,1) (10,1) and I have a nonlinear line on the x y plane and I need to find the difference between the linear and nonlinear curve
  2 件のコメント
KSSV
KSSV 2020 年 10 月 18 日
編集済み: KSSV 2020 年 10 月 18 日
Do you have points i.e (x ,y) for the nonlinesr curve?
If so, make points for line equal in number to curve with same x values...and subtract the y-values.
VBBV
VBBV 2020 年 10 月 18 日
% if true
% code
% end
K = 2.5;
X = linspace(-10,10,100);
Y = K*((X/20)).^3;
Ly = ones(1,100);
Diff = Ly - Y;
plot(X,Diff,'r',X,Ly,'k',X,Y,'b');
legend('Diff','linear','nonlinear');

サインインしてコメントする。

回答 (1 件)

Manvi Goel
Manvi Goel 2020 年 10 月 29 日
You can plot the difference between the two lines by simply passing the second argument to the plot function as y - z where y and z are the two lines respectively.
X = linspace(-10,10,100); %line 1
Y = sin(X); %line 2
Z = ones(1,100);
plot(X, Y - Z); %plot for the difference

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by