EULER'S METHOD GUI HELP
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Rik
on 9 Apr 2019
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 Comments
Rik
on 9 Apr 2019
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.
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!