【问题标题】:Matlab: plot Cubic function for range of y valuesMatlab:绘制y值范围的三次函数
【发布时间】:2015-12-01 11:21:53
【问题描述】:

我有一个三次方程:

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 范围并且拟合看起来错误。

【问题讨论】:

    标签: matlab cubic


    【解决方案1】:

    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')
    

    这给出了以下情节:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-27
      • 2012-05-07
      • 2014-07-10
      • 1970-01-01
      • 2019-11-17
      • 1970-01-01
      相关资源
      最近更新 更多