[問題] 關於自定function已回收

看板MATLAB作者 (wsone)時間17年前 (2008/10/29 22:37), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
請問大家一個簡單的問題, (我是初學者,也爬過文和試著去看help,但還是看不懂><) 我打了一個M檔案如下: function v=func(x) v = 816*x^3-3835*x^2+6000*x-3125 ; 除錯後,顯示: ??? Input argument "x" is undefined. Error in ==> func at 2 v = 816*x^3-3835*x^2+6000*x-3125 ; 為什麼不行執行呢? 因為我想寫一個關於牛頓法的程式如下: function [res, it] = mynewton(func, dfunc, x, tol) % x is an initial starting value, tol is required accuracy it = 0; x0 = x; d = feval(@func,x0)/feval(@dfunc,x0); while abs(d) >tol x1 = x0-d; it = it+1; x0 = x; d = feval(@func,x0)/feval(@dfunc,x0); end res = x0; 除錯後,顯示: ??? Error: File: mynewton.m Line: 5 Column: 12 "func" was previously used as a variable, conflicting with its use here as the name of a function or command. See MATLAB Programming, "Determining Which Function Is Called" for details. 到底錯在哪裡?請大家幫忙回答,謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.7.59

10/29 22:54, , 1F
你該不會是直接執行function吧
10/29 22:54, 1F
文章代碼(AID): #1927L1qW (MATLAB)
文章代碼(AID): #1927L1qW (MATLAB)