Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How can I use integral function this way?

2 ビュー (過去 30 日間)
Aparicio Nieto
Aparicio Nieto 2017 年 3 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
function [mat_uni] = mat_unif(i,j,k,s,ro,h_b,x_b1,x_b2)
fi_jk = 2./sqrt(3).*pi.^(-1./4).*2.^(j./2).*(1-(2.^j.*x-k).^2).*exp(-(2.^j.*x-k).^2./2);
fi_is = 2./sqrt(3).*pi.^(-1./4).*2.^(i./2).*(1-(2.^i.*x-s).^2).*exp(-(2.^i.*x-s).^2./2);
mat_uni_der = @(x) 2.*ro.*h_b.*fi_jk.*fi_is;
mat_uni = integral(mat_uni_der, x_b1, x_b2);
end
The problems when integrating this function come from calling fi_jk and fi_is functions, since matlab does not recognize x as a variable that will later be used by integral().
If I delete the 'x' as an input, I am told that there are not enough input arguments. I have tried to define x using 'syms x', but other errors appeared: 'Input function must return 'double' or 'single' values. Found 'sym''.
Could it be useful to use the function handle? If so, how to use it?
Also, I would like to know what "opstruct" is used for.
Thank you very much for the possible answers.
  2 件のコメント
Jan
Jan 2017 年 3 月 22 日
編集済み: Jan 2017 年 3 月 22 日
What is "x" in the inputs? A vector or a symbolic variable?
Aparicio Nieto
Aparicio Nieto 2017 年 3 月 22 日
編集済み: Aparicio Nieto 2017 年 3 月 23 日
It is a variable, since I want the integral function to give me a numerical value, but I do not know how to define it without having to define it as an input argument (it does not come from the main program).

回答 (2 件)

Walter Roberson
Walter Roberson 2017 年 3 月 23 日
function [mat_uni] = mat_unif(i,j,k,s,ro,h_b,x_b1,x_b2)
fi_jk = @(x) 2./sqrt(3).*pi.^(-1./4).*2.^(j./2).*(1-(2.^j.*x-k).^2).*exp(-(2.^j.*x-k).^2./2);
fi_is = @(x) 2./sqrt(3).*pi.^(-1./4).*2.^(i./2).*(1-(2.^i.*x-s).^2).*exp(-(2.^i.*x-s).^2./2);
mat_uni_der = @(x) 2.*ro.*h_b.*fi_jk(x).*fi_is(x);
mat_uni = integral(mat_uni_der, x_b1, x_b2);
end

Roger Stafford
Roger Stafford 2017 年 3 月 23 日
I think it will work if you simply substitute those two expressions for fi_jk and fi_is, respectively, into the anonymous function mat_uni_der. It will make a very long line, but who cares about long lines? Getting it to work is what counts.
  2 件のコメント
Aparicio Nieto
Aparicio Nieto 2017 年 3 月 23 日
Yes! It works if I do what you say, but now I want to integrate a function that is diff(f) and writing all this stuff would be terrible. I have tried to use syms, but it has been all night working and I have not seen any result yet.
Thank you very much for your answer!
Walter Roberson
Walter Roberson 2017 年 3 月 23 日
You could do numeric differentiation on a sampling of function values. Or you can use
syms x
dx = diff( mat_uni_der(x), x)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by