Input function must return 'double' or 'single' values. Found 'sym'.
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
dear all
when i using integral command although i define z i get the following error
clc
clear all
E2=10;
E1=20;
lE=E2/E1;
n=1;
h=2;
v1=30;
v2=40;
lv=v2/v1;
sym z
Eb=1+(((2*z+h)/2*h)^n)*(lE-1)
vb=1+(((2*z+h)/2*h)^n)*(lv-1)
fun=@(z) Eb/((1-(v1^2)*(vb^2))*h)
A11=integral(fun,-1/2,1/2)
and the error :
Undefined function or variable 'z'.
Error in first (line 13)
Eb=1+(((2*z+h)/2*h)^n)*(lE-1)
and also when i use syms z instead of sym z i get the following one :
fun =
function_handle with value:
@(z)Eb/((1-(v1^2)*(vb^2))*h)
Error using integralCalc/finalInputChecks (line 511)
Input function must return 'double' or 'single' values. Found 'sym'.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in first (line 18)
A11=integral(fun,-1/2,1/2)
i really appreciated if someone could help me with this
採用された回答
Correct syntax is to use 'syms', not 'sym'. Also you should use matlabFunction to convert symbolic equation to numeric
clc
clear all
E2=10;
E1=20;
lE=E2/E1;
n=1;
h=2;
v1=30;
v2=40;
lv=v2/v1;
syms z
Eb=1+(((2*z+h)/2*h)^n)*(lE-1)
vb=1+(((2*z+h)/2*h)^n)*(lv-1)
fun= matlabFunction(Eb/((1-(v1^2)*(vb^2))*h))
A11=integral(fun,-1/2,1/2)
12 件のコメント
dear ameer tanx alot about ur answer
i try it and it work but why when i use equal E1 and E2 (E1=E2) i get the following error :
Error using symengine>@()-3.126954346466542e-4
Too many input arguments.
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] =
iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in first (line 24)
A11=integral(fun,-1/2,1/2)
i should mentioned that when i use E1=E2
fun=1
shahin, can you paste your code here. I cannot understand how you made E1=E2.
clc
clear all
E2=20;
E1=20;
lE=E2/E1;
n=1;
h=2;
v1=30;
v2=40;
lv=v2/v1;
syms z
Eb=1+(((2*z+h)/2*h)^n)*(lE-1)
vb=1+(((2*z+h)/2*h)^n)*(lv-1)
fun= matlabFunction(Eb/((1-(v1^2)*(vb^2))*h))
A11=integral(fun,-1/2,1/2)
as u say
Shahin, running your code, I don't get any error, I get the following output
Eb =
1
vb =
(2*z)/3 + 5/3
fun =
function_handle with value:
@(z)-1.0./((z.*(2.0./3.0)+5.0./3.0).^2.*1.8e+3-2.0)
A11 =
-2.084250038383697e-04
Can you paste the value of 'fun' after running your code. It should be a function handle, paste the output from command window.
clc
clear all
d=10;
E2=30;
E1=30;
lE=E2/E1;
n=1;
h=2;
v1=40;
v2=40;
lv=v2/v1;
l1=30;
l2=30;
ll=l2/l1;
i=2;
syms z
Eb=(1+(((2*z+h)/2*h)^n)*(lE-1))
vb=(1+(((2*z+h)/2*h)^n)*(lv-1))
lb=(1+(((2*z+h)/2*h)^n)*(ll-1))
fun= matlabFunction(Eb/((1-(v1^2)*(vb^2))*h))
A11=integral(fun,-1/2,1/2)
this is what i exactly try to run
and as u say this is what i exactly get :
fun =
function_handle with value:
@()-3.126954346466542e-4
Error using symengine>@()-3.126954346466542e-4
Too many input arguments.
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] =
iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in first (line 25)
A11=integral(fun,-1/2,1/2)
im really sorry to bother u and really appreciate about your help
and i should mention that i can run this cod like this :
fun=@(z) (1+(((2*z+h)/2*h)^n)*(lE-1))/(1-(v1.^2).*((1+(((2*z+h)/2*h)^n)*(lv-1))^2)*h);
A11=integral(fun,-1/2,1/2,'ArrayValued',true)
Shahin, for this case, your function is just a constant value and not a function of z, this created issue with the integral function. In this case, try
d=10;
E2=30;
E1=30;
lE=E2/E1;
n=1;
h=2;
v1=40;
v2=40;
lv=v2/v1;
l1=30;
l2=30;
ll=l2/l1;
i=2;
syms z
Eb=(1+(((2*z+h)/2*h)^n)*(lE-1))
vb=(1+(((2*z+h)/2*h)^n)*(lv-1))
lb=(1+(((2*z+h)/2*h)^n)*(ll-1))
fun = matlabFunction(Eb/((1-(v1^2)*(vb^2))*h))
A11=integral(@(x) fun(),-1/2,1/2, 'ArrayValued', 1)
aha got
as i usnderstand we cant have cod that handle both situation
tanx a lot again
d=10;
E2=30;
E1=30;
lE=E2/E1;
n=1;
h=2;
v1=40;
v2=40;
lv=v2/v1;
l1=30;
l2=30;
ll=l2/l1;
i=2;
syms z
Eb=(1+(((2*z+h)/2*h)^n)*(lE-1))
vb=(1+(((2*z+h)/2*h)^n)*(lv-1))
lb=(1+(((2*z+h)/2*h)^n)*(ll-1))
if E1==E2
fun = matlabFunction(Eb/((1-(v1^2)*(vb^2))*h))
A11=integral(@(x) fun(),-1/2,1/2, 'ArrayValued', 1)
else
fun= matlabFunction(Eb/((1-(v1^2)*(vb^2))*h))
A11=integral(fun,-1/2,1/2)
end
i use like this
Ameer Hamza
2020 年 4 月 8 日
編集済み: Ameer Hamza
2020 年 4 月 8 日
Your solution is correct. You can also use this to avoid if-else block
d=10;
E2=30;
E1=10;
lE=E2/E1;
n=1;
h=2;
v1=40;
v2=40;
lv=v2/v1;
l1=30;
l2=30;
ll=l2/l1;
i=2;
syms z
Eb=(1+(((2*z+h)/2*h)^n)*(lE-1))
vb=(1+(((2*z+h)/2*h)^n)*(lv-1))
lb=(1+(((2*z+h)/2*h)^n)*(ll-1))
sum_fun(z) = Eb/((1-(v1^2)*(vb^2))*h); % this lines forces it to act as a function of z, even if the value is constant
fun = matlabFunction(sum_fun)
A11=integral(fun,-1/2,1/2, 'ArrayValued', 1)
wow you are my hero :D tanx
Glad to be of help :D
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
