Question: I have this lab I am trying to complete, it is Coding in MATLAB. I was curious how to fix an error I keep receiving.
I have this lab I am trying to complete, it is Coding in MATLAB. I was curious how to fix an error I keep receiving.
%%%Error%%%
Error using sym/subsindex (line 853)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function
arguments must be symbolic variables, and function body must be sym expression.
Error in Lab9Math2130ahalvors (line 11)
%%% Code %%%
f(x,y)= k*y;
num= 0970974;%student number
k= num/1000000;
syms y;
syms x;
f(x,y)= k*y;
x0= 0;
y0= 1;
h= 0.05;
x= x0;
y= y0;
t= 2;
while x<= t%euler's method
y= y+h*double(f(x,y));
x= x+h;
end
eulerY= y
x= x0;
y= y0;
while x<= t%midpoint method
k1= h*double(f(x ,y));
k2= h*double(f(x+0.5*h, y+0.5*k1));
y= y+k2;
x= x+h;
end
midpointY= y
x= 2;
realY= exp(k*x)%solution to the diffrential eq
RErrorEulers= abs(realY-eulerY)/realY
RErrorMidpoint= abs(realY-midpointY)/realY
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
