EULER'S METHOD GUI HELP

1 回表示 (過去 30 日間)
Gatz Gold
Gatz Gold 2019 年 4 月 9 日
コメント済み: Gatz Gold 2019 年 4 月 9 日
The y values of my euler method keeps on having a result of NaN's except for it's first value.
here is the code for the push button callback.
% --- Executes on button press in eul_solve.
function eul_solve_Callback(hObject, eventdata, handles)
% hObject handle to eul_solve (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
m = str2double(get(handles.iterations, 'string'));
t = zeros (m+1,0);
y = zeros (size(t));
h = str2double(get(handles.stepsize, 'string'));
t(1) = str2num(get(handles.tval, 'string')); %1st value of t
y(1) = str2num(get(handles.eul_ic, 'string')); %initial condition
for n = 1:m
t(n+1)=t(n)+h;
y(n+1)=y(n)+h.*(str2double(get(handles.eqn, 'string')));
end
result1 = t;
result2 = y;
result = ([t,y]);
set(handles.result1, 'string', result1);
set(handles.result2, 'string', result2);
could someone please point out where I've been wrong so that the y values will be displayed.

回答 (1 件)

Rik
Rik 2019 年 4 月 9 日
You are using str2num (which you shouldn't), and you are setting a numeric vector as the string property. You may need to consider selecting only a single value, and you need to convert the number to a char (eg with sprintf).
  3 件のコメント
Rik
Rik 2019 年 4 月 9 日
You should read the documentation for the functions you are using. The Matlab documentation is very good, it is one of the advantages over their competitors.
If you open the doc for str2num you will see a banner telling you to use str2double instead.
Gatz Gold
Gatz Gold 2019 年 4 月 9 日
Thank you! I'll consider reading more about it.

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

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by