フィルターのクリア

"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:
Dyuman Joshi
Dyuman Joshi 2023 年 12 月 21 日
+1 to Torsten's suggestion of MATLAB Onramp

サインインしてコメントする。

回答 (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 Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by