gpt4 book ai didi

matlab - polyfit 和 polyval 函数

转载 作者:太空宇宙 更新时间:2023-11-03 20:01:14 25 4
gpt4 key购买 nike

<分区>

你好,我的问题是关于 P3(x) 的曲线 tiffing 我使用 polyfit 和 polyval 函数编写我的代码,但我需要在不使用这些函数的情况下实现它。

这是我写的代码

n=input('Enter a value: ');
if(n<3)
fprintf('Enter a different value larger than 3')
end
if(n>=3)
x = 1:n;
y = -0.3*x + 2*randn(1,n);
[p,S] = polyfit(x,y,3);
[y_fit,delta] = polyval(p,x,S);
plot(x,y,'bo')
hold on
plot(x,y_fit,'r-')
title('Linear-Fit Output')
legend('Data','Linear Fit')
end

这是我编写的代码,它可以工作,但我想在不使用 polfite 和 polyval 函数的情况下编写它

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com