Help for error using eval() in for loop

2 views (last 30 days)
Karl  Meyer
Karl Meyer on 13 Mar 2015
Edited: Karl Meyer on 13 Mar 2015
I am running the following for loop for a numeric simpson-integration:
if true
syms x
f(x)=sin(x.^4);
a=-4/3;b=4/3;
for m=2.^[1:10];
n=2.*m;
h=(b-a)./n;
%simpson-script
x1=(a:b);
x2=(a+h:2*h:b-h);
x3=(a+2*h:2*h:b-2*h);
sum1=sum(f(x1));
sum2=sum(f(x2));
sum3=sum(f(x3));
A=(h/3)*(sum1+4*sum2+2*sum3);
%Error estimation
Aexact=int(f(x),a,b);%<- the analytic exact result
eval(A);
error=(Aexact-eval(A));
eval(error)
end
At this point matlab returns the following error message:
Error using vertcat Dimensions of matrices being concatenated are not consistent.
Error in sym/eval (line 11) s = evalin('caller',vectorize(map2mat(char(x))));
Does anyone know how to resolve this?

Answers (0)

Community Treasure Hunt

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

Start Hunting!