why im getting error in table and i have 2013 version.
1 view (last 30 days)
Show older comments
clc;
clear all;
close all;
%% First Part
h=0.01; %given
%initial Value Given
y(1)=2;
t=0:h:1;
%diff_fun=1+t-y-t*y;
%% Coefficients from Butcher array
c1=0;
c2=1/2;
c3=1;
b1=1/6;
b2=2/3;
b3=1/6;
a21=1/2;
a31=-1;
a32=2;
%% Genral Form of Raltson Method
%y(n+1)=y(n)+b1*k1+b2*k2+b3*k3
% k1=h*f(t1,y1)
% k2=h*f(t1+c2*h,y1+a21*k1)
% k3=h*f(t1+c3*h,y1+a31*k1+a32*k2)
for i=2:length(t)
k1=h*(1+t(i-1)-y(i-1)-t(i-1)*y(i-1));
k2=h*(1+(t(i-1)+c2*h)-(y(i-1)+a21*k1)-(t(i-1)+c2*h)*(y(i-1)+a21*k1));
k3=h*(1+(t(i-1)+c3*h)-(y(i-1)+a31*k1+a32*k2)-(t(i-1)+c3*h)*(y(i-1)+a31*k1+a32*k2));
y(i)=y(i-1)+b1*k1+b2*k2+b3*k3;
end
%To Create Table and relative error
t_data=[0.2,0.4,0.6,0.8,1];
y_exact=(1+exp(-t_data-(t_data.^2)/2));
[tf,idx]=ismember(t_data,t);
Approx_Value=(y(idx));
Raltive_Error=(((y_exact-Approx_Value)./y_exact))';
y_exact=(1+exp(-t_data-(t_data.^2)/2))';
SlNo=[1:5]';
Approx_Value=(y(idx))';
t_data=[0.2,0.4,0.6,0.8,1]';
T=table(SlNo,t_data,y_exact,Approx_Value,Raltive_Error)
%% Done
8 Comments
Adam Danz
on 12 Nov 2019
In that case, you can work with a cell array instead of a table.
T={SlNo,t_data,y_exact,Approx_Value,Raltive_Error}
assuming each variable is a column of equal length.
If the variables are all numeric, a matrix may be better
T=[SlNo,t_data,y_exact,Approx_Value,Raltive_Error]
Walter Roberson
on 12 Nov 2019
Also if you have Statistics toolbox you might be able to use dataset()
Answers (0)
See Also
Categories
Find more on Tables 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!