Can't define functions in Matlab

4 ビュー (過去 30 日間)
Pedro
Pedro 2012 年 9 月 4 日
Hello everyone, I have version R2012a of matlab and I would like to define this function to create direccional fields on first order differential equations. I created a notepad file with this code on it and exchanged the extension from .txt to .m and placed it on MATLAB/R2012a but it doesnt work. What am I doing wrong? Is it the folder? I also tried to put the code directily on matlab and run it but it failed.
function dirfield(f,tval,yval)
[tm,ym]=meshgrid(tval,yval);
dt = tval(2) - tval(1);
dy = yval(2) - yval(1);
yp=feval(vectorize(f),tm,ym);
s = 1./max(1/dt,abs(yp)./dy)*0.35;
h = ishold;
quiver(tval,yval,s,s.*yp,0,'.r'); hold on;
quiver(tval,yval,-s,-s.*yp,0,'.r');
if h
hold on
else
hold off
end
axis([tval(1)-dt/2,tval(end)+dt/2,yval(1)-dy/2,yval(end)+dy/2])
I would apreciate your help!
  1 件のコメント
Jan
Jan 2012 年 9 月 4 日
What does "placed it on MATLAB/R2012a" exactly mean?

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

採用された回答

Matt Fig
Matt Fig 2012 年 9 月 4 日
At the command prompt, type: edit
Now paste your code into the window that opens up. Then save it. From the commamd prompt use the same name as you saved the file.

その他の回答 (2 件)

Elizabeth
Elizabeth 2012 年 9 月 4 日
Your function name must match the file name you save it under. Could this be the issue?

Pedro
Pedro 2012 年 9 月 4 日
編集済み: Pedro 2012 年 9 月 4 日
Thanks, I did what you said and it saved it on MATLAB/R2012a/bin , it had to be there. By the way, do these programs work on mathematica too?

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by