Euler's Method plot?

조회 수: 4 (최근 30일)
Lily Mcmon
Lily Mcmon 2019년 4월 22일
편집: darova 2019년 4월 22일
i'm having some trouble coding a eulers method code and creating a plot. here is what i have so far. how can i do the code for run_eulers_method and plot_results? sorry for english
function [] = L12_Q03 ()
y = @(t) t* cos(t 1) + t
f = @(t,w) t *sin(t 1) + w/t
y1 = 0;
w1 = 0;
t1 = 1;
tn = 10;
get_step_size();
run_eulers_method();
end
function [] = get_step_size()
h = input('Enter a step size h: ');
while h <=0 || abs(h - floor(h)) > 1e-8
fprintf('Invalid entry %d \n', steps);
h = input('Enter a step size h: ');
end
end
function [] = run_eulers_method(y,f,h, ,t1, tn, w1)
t = t1:h:tn;
wnext = w1 + h*f(t1,w1)
e = abs(y1 - w1);
fprintf('The average absolute error in the approximation is %0.5f \n', e);
plot_results();
end
function [] = plot_results(y,t1, h, tn, t, w)
figure(1);
clf;
plot(1:y, w, 'ob');
xlabel('Time');
ylabel('Function Value');
print('-dpng', 'newtons_method_approx.png');
end
  댓글 수: 1
darova
darova 2019년 4월 22일
편집: darova 2019년 4월 22일
You have to learn how functions work
clc, clear
h = get_step_size();
disp(h)
function h = get_step_size()
h = input('Enter a step size h: ');
while h <=0 || abs(h - floor(h)) > 1e-8
fprintf('Invalid entry %d \n', steps);
h = input('Enter a step size h: ');
end
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by