필터 지우기
필터 지우기

"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 (최근 30일)
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
Torsten
Torsten 2023년 12월 21일
If you are new to MATLAB and you want to know what you are doing, invest 2 hours of your time and pass an introductionary course for free:

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 12월 21일
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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by