[英]How do I solve a function for x in Matlab?
我定義了此功能:
% Enter the data that was recorded into two vectors, mass and period
mass = 0 : 200 : 1200;
period = [0.404841 0.444772 0.486921 0.522002 0.558513 0.589238 0.622942];
% Calculate a line of best fit for the data using polyfit()
p = polyfit(mass, period, 1);
fit=@(x) p(1).*x + p(2);
現在我想求解f(x)= .440086,但是找不到解決方法。 我知道我可以輕松地手工解決,但是我想知道將來如何做。
如果要求解線性方程,例如A*x+B=0
,則可以在MATLAB中輕松求解,如下所示:
p=[0.2 0.5];
constValue=0.440086;
A=p(1);
B=constValue-p(2);
soln=A\B;
如果要求解非線性方程組,則可以按以下方式使用fsolve
(在此,我將展示如何使用它來求解上述線性方程):
myFunSO=@(x)0.2*x+0.5-0.440086; %here you are solving f(x)-0.440086=0
x=fsolve(myFunSO,0.5) %0.5 is the initial guess.
兩種方法都應為您提供相同的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.