Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB Table Interval Help needed I have the following code: myfunction = @(x, y

ID: 3281694 • Letter: M

Question

MATLAB Table Interval Help needed

I have the following code:

myfunction = @(x, y) -.04*y -9.8;

x0 = 0;

xf = 10;

y0 = 49;

h = 0.1;

N = (xf - x0)/h;

[t1,v1]= euler(myfunction, x0, xf, y0, N);

h = 0.05;

N = (xf - x0)/h;

[t2,v2]= euler(myfunction, x0, xf, y0, N);

func = @(x) [294*exp(-.04*x) - 245];

v1exact = arrayfun(func,t1);

v2exact = arrayfun(func,t2);

Errorv1 = abs(v1exact - v1)

Errorv2 = abs(v2exact - v2)

T01 = table(t1,v1, v1exact, Errorv1)

T05 = table(t2,v2, v2exact, Errorv2)

It uses a custom Euler's method script that works as it should. The only issue I am having is the tables generated at the end. The two tables I get have t displayed in intervals of 0.1 and 0.05. These are the subintervals I need for the Euler calculations, so I cannot change the N or h values in the script. However, I only want to see the results displayed with t intervals of 1 in the table. Since t stops at 10, there should only be ten total values of t in the table (or 11 if you count zero). Right now the tables have 101 and 201 values of t. Any idea of how to tackle that?

Explanation / Answer

for table one you have h=0.1

so N=(10-0)/0.1=100

thus total 101 value including position t=0 too

So if you want to check only value of t=1,2,3,4,5,6,7,8,9 and 10

then you have to give a gap of 10 in t1 and 20 in t2

T01 = table(t1(1:10:end),v1(1:10:end), v1exact(1:10:end), Errorv1(1:10:end))

T05 = table(t2(1:20:end),v2(1:20:end), v2exact(1:20:end), Errorv2(1:20:end))