The figure in my code does not appear

The code i am working on is the euler's method for BVP. The code runs without an error but the plot window appears with no graph in it, why does this happen? and how can i fix it?

 Accepted Answer

USe marker. As you are plottint point by point.
clc; close ;clear all
A = 2 ;
Kc = 1 ;
t1 = 0.1 ;
delta_h = 0 ;
h = 0.1 ;
z = 2 ;
figure
hold on
for t = 0:h:10
delta_h_next = delta_h + (z * h) ;
z_next = z - ((Kc/A)*z+((Kc/(A*t1)*delta_h))*h) ;
delta_h = delta_h_next ;
z = z_next ;
fprintf('%5.4f %11.8f \n', t, delta_h);
plot(delta_h,t,'*-r')
end
0.0000 0.20000000 0.1000 0.30000000 0.2000 0.34000000 0.3000 0.34500000 0.4000 0.33050000 0.5000 0.30600000 0.6000 0.27722500 0.7000 0.24753750 0.8000 0.21883250 0.9000 0.19210313 1.0000 0.16779681 1.1000 0.14603850 1.2000 0.12676950 1.3000 0.10983308 1.4000 0.09502639 1.5000 0.08213140 1.6000 0.07093258 1.7000 0.06122660 1.8000 0.05282698 1.9000 0.04556584 2.0000 0.03929392 2.1000 0.03387967 2.2000 0.02920785 2.3000 0.02517795 2.4000 0.02170262 2.5000 0.01870605 2.6000 0.01612263 2.7000 0.01389562 2.8000 0.01197599 2.9000 0.01032139 3.0000 0.00889529 3.1000 0.00766617 3.2000 0.00660685 3.3000 0.00569388 3.4000 0.00490705 3.5000 0.00422894 3.6000 0.00364453 3.7000 0.00314088 3.8000 0.00270683 3.9000 0.00233276 4.0000 0.00201039 4.1000 0.00173256 4.2000 0.00149313 4.3000 0.00128678 4.4000 0.00110895 4.5000 0.00095570 4.6000 0.00082363 4.7000 0.00070980 4.8000 0.00061171 4.9000 0.00052718 5.0000 0.00045432 5.1000 0.00039154 5.2000 0.00033743 5.3000 0.00029080 5.4000 0.00025061 5.5000 0.00021598 5.6000 0.00018613 5.7000 0.00016041 5.8000 0.00013824 5.9000 0.00011913 6.0000 0.00010267 6.1000 0.00008848 6.2000 0.00007625 6.3000 0.00006572 6.4000 0.00005663 6.5000 0.00004881 6.6000 0.00004206 6.7000 0.00003625 6.8000 0.00003124 6.9000 0.00002692 7.0000 0.00002320 7.1000 0.00002000 7.2000 0.00001723 7.3000 0.00001485 7.4000 0.00001280 7.5000 0.00001103 7.6000 0.00000951 7.7000 0.00000819 7.8000 0.00000706 7.9000 0.00000608 8.0000 0.00000524 8.1000 0.00000452 8.2000 0.00000389 8.3000 0.00000336 8.4000 0.00000289 8.5000 0.00000249 8.6000 0.00000215 8.7000 0.00000185 8.8000 0.00000160 8.9000 0.00000137 9.0000 0.00000118 9.1000 0.00000102 9.2000 0.00000088 9.3000 0.00000076 9.4000 0.00000065 9.5000 0.00000056 9.6000 0.00000049 9.7000 0.00000042 9.8000 0.00000036 9.9000 0.00000031 10.0000 0.00000027

More Answers (1)

Also you can save them into an array and plot after the loop:
A = 2 ;
Kc = 1 ;
t1 = 0.1 ;
delta_h = 0 ;
h = 0.1 ;
z = 2 ;
count = 0 ;
x = zeros([],1) ;
y = zeros([],1) ;
for t = 0:h:10
count = count+1 ;
delta_h_next = delta_h + (z * h) ;
z_next = z - ((Kc/A)*z+((Kc/(A*t1)*delta_h))*h) ;
delta_h = delta_h_next ;
z = z_next ;
fprintf('%5.4f %11.8f \n', t, delta_h);
x(count) = delta_h ;
y(count) = t ;
end
0.0000 0.20000000 0.1000 0.30000000 0.2000 0.34000000 0.3000 0.34500000 0.4000 0.33050000 0.5000 0.30600000 0.6000 0.27722500 0.7000 0.24753750 0.8000 0.21883250 0.9000 0.19210313 1.0000 0.16779681 1.1000 0.14603850 1.2000 0.12676950 1.3000 0.10983308 1.4000 0.09502639 1.5000 0.08213140 1.6000 0.07093258 1.7000 0.06122660 1.8000 0.05282698 1.9000 0.04556584 2.0000 0.03929392 2.1000 0.03387967 2.2000 0.02920785 2.3000 0.02517795 2.4000 0.02170262 2.5000 0.01870605 2.6000 0.01612263 2.7000 0.01389562 2.8000 0.01197599 2.9000 0.01032139 3.0000 0.00889529 3.1000 0.00766617 3.2000 0.00660685 3.3000 0.00569388 3.4000 0.00490705 3.5000 0.00422894 3.6000 0.00364453 3.7000 0.00314088 3.8000 0.00270683 3.9000 0.00233276 4.0000 0.00201039 4.1000 0.00173256 4.2000 0.00149313 4.3000 0.00128678 4.4000 0.00110895 4.5000 0.00095570 4.6000 0.00082363 4.7000 0.00070980 4.8000 0.00061171 4.9000 0.00052718 5.0000 0.00045432 5.1000 0.00039154 5.2000 0.00033743 5.3000 0.00029080 5.4000 0.00025061 5.5000 0.00021598 5.6000 0.00018613 5.7000 0.00016041 5.8000 0.00013824 5.9000 0.00011913 6.0000 0.00010267 6.1000 0.00008848 6.2000 0.00007625 6.3000 0.00006572 6.4000 0.00005663 6.5000 0.00004881 6.6000 0.00004206 6.7000 0.00003625 6.8000 0.00003124 6.9000 0.00002692 7.0000 0.00002320 7.1000 0.00002000 7.2000 0.00001723 7.3000 0.00001485 7.4000 0.00001280 7.5000 0.00001103 7.6000 0.00000951 7.7000 0.00000819 7.8000 0.00000706 7.9000 0.00000608 8.0000 0.00000524 8.1000 0.00000452 8.2000 0.00000389 8.3000 0.00000336 8.4000 0.00000289 8.5000 0.00000249 8.6000 0.00000215 8.7000 0.00000185 8.8000 0.00000160 8.9000 0.00000137 9.0000 0.00000118 9.1000 0.00000102 9.2000 0.00000088 9.3000 0.00000076 9.4000 0.00000065 9.5000 0.00000056 9.6000 0.00000049 9.7000 0.00000042 9.8000 0.00000036 9.9000 0.00000031 10.0000 0.00000027
plot(x,y)

Categories

Products

Tags

Asked:

on 16 Jan 2022

Answered:

on 16 Jan 2022

Community Treasure Hunt

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

Start Hunting!