adding functions in a m file instead in the command line

2 ビュー (過去 30 日間)
ARUN BORGOHAIN
ARUN BORGOHAIN 2017 年 6 月 20 日
コメント済み: Walter Roberson 2017 年 6 月 20 日
function x=mynewton (f,f1 ,x ,n)
x=0.1; % initial guess x0
n=100;
for i = 1:n
x = x - f(x) / f1(x); % Newton 's formula
end
x
Sir, I would like to declare these (f & f1) inside m file; pl. help
f = @(x) x^3 - 5
f1 = @(x) 3*x^2

採用された回答

Walter Roberson
Walter Roberson 2017 年 6 月 20 日
If you are using R2016b or later, you can put those two lines at the top of the .m file to create a script; you would then want to also put in a call to your mynewton function
If you are using R2016a or earlier, then you will need to put them into a different .m that you run before you call upon myNewton.
  2 件のコメント
ARUN BORGOHAIN
ARUN BORGOHAIN 2017 年 6 月 20 日
Thanks ; I am using much older version; pl add some patchup files in matlab site s.t i can get the facilities of R2016b!
Walter Roberson
Walter Roberson 2017 年 6 月 20 日
There are no patch-up files for that purpose. You can purchase a newer version of MATLAB.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler SDK についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by