簡體   English   中英

Matlab:為y值范圍繪制三次函數

[英]Matlab: plot Cubic function for range of y values

我有一個三次方程式:

roots([9E-10 -2E-06 0.0014 0.039])

我正在嘗試繪制0.0到0.5的y值的方程(我知道x值在0到700的范圍內。(即,方程已經適合此數據)

r=0.0039-y; %where y ranges from 0.0 to 0.5
[eqnroots]=roots([9E-10 -2E-06 0.0014 r])

我找到了真正的根

isreal(eqnroots(n));

然后繪制方程式,但它沒有給出正確的x / y范圍,並且擬合看起來是錯誤的。

roots函數僅產生多項式方程的根。 要為給定的一組x值生成所有y值,您需要使用polyval

嘗試這個:

% Polynomial coefficients
p = [9E-10 -2E-06 0.0014 0.039];

% Generate y-values for x-range we are interested in
x = -270:0.1:1350;
y = polyval(p,x);

% Find roots of the polynomial.
% Select any where the imaginary component is negligible, i.e. it is real.
% As it's a root, the corresponding y-value will be 0.
xroot = roots(p);
xroot = xroot(abs(imag(xroot)) < 1e-10);
yroot = zeros(size(xroot));

% Plot the polynomial and its real roots.
figure;
hold on
plot(x,y, 'b')
plot(xroot,yroot, 'rx')

這給出了以下圖:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM