Clear Filters
Clear Filters

"Execution of script cfunc as a function is not supported" i don't understand why i get this error, i tried making a function on multiple intervals

2 views (last 30 days)
L=0;
A1=-0.0036;
A2=-0089;
A3=8.75e-4;
B1=1.8e-5;
B2=2.7188e-5;
B3=-4.5e-6;
L1=0.0035;
L2=0.003;
L3=0.0055;
x=(0:0.0001:L3);
function c = func(x,L1,L2,L3)
c1 = @(x)(A1*x+B1);
c2 = @(x)(E/(2*D)*(x^2)+A2*x+B2);
c3 = @(x)(A3*x+B3);
if (x>=0 && x<L1)
c=c1(x);
end
if(x>=L1 && x<L2+L1)
c=c2(x);
end
if(x>=L1+L2 && x<=L1+L2+L3)
c=c3(x);
end
end
  9 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 21 Dec 2023
You do not define D or E
L=0;
A1=-0.0036;
A2=-0089;
A3=8.75e-4;
B1=1.8e-5;
B2=2.7188e-5;
B3=-4.5e-6;
L1=0.0035;
L2=0.003;
L3=0.0055;
x=(0:0.0001:L3);
y = arrayfun(@(X)func(X,L1,L2,L3,A1,A2,A3,B1,B2,B3), x);
Unrecognized function or variable 'E'.

Error in solution>@(x)(E/(2*D)*(x^2)+A2*x+B2) (line 17)
c2 = @(x)(E/(2*D)*(x^2)+A2*x+B2);

Error in solution>func (line 23)
c=c2(x);

Error in solution>@(X)func(X,L1,L2,L3,A1,A2,A3,B1,B2,B3) (line 12)
y = arrayfun(@(X)func(X,L1,L2,L3,A1,A2,A3,B1,B2,B3), x);
plot(x, y)
function c = func(x,L1,L2,L3,A1,A2,A3,B1,B2,B3)
c1 = @(x)(A1*x+B1);
c2 = @(x)(E/(2*D)*(x^2)+A2*x+B2);
c3 = @(x)(A3*x+B3);
if (x>=0 && x<L1)
c=c1(x);
end
if(x>=L1 && x<L2+L1)
c=c2(x);
end
if(x>=L1+L2 && x<=L1+L2+L3)
c=c3(x);
end
end

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!