How to multiply function handles?
古いコメントを表示
Hello,
I would like to calculate and to plot the following equation:
f(t,x) = (beta_hat*s(t,x)*[I(t,x)]^(beta_hat-1))*exp(-[I(t,x)]^beta_hat)
where:
s(t,x): step-function(330 for x=[0;2000])
(350 for x=[2000;3000])
(390 for x=[3000;4000])
I(t,x): Integral(exp(-B_hat/x(u))/C_hat)) from x=0 to t
beta_hat, C_hat and B_hat are known parameters
My MATLAB-script looks like that:
beta_hat = 4.2915822
B_hat = 1861.6186657
C_hat = 58.9848692
%%Step-function x(t)
syms t
y(t) = (exp(-B_hat/((heaviside(t)-heaviside(t-2000))*(330)+(heaviside(t-2000)-heaviside(t-3000))*(350)+...
(heaviside(t-3000)-heaviside(t-4000))*(390))))/C_hat;
fnum=matlabFunction(y);
Inum=@(x)integral(fnum,0,x);
f = @(x)(beta_hat*fnum(x).*Inum(x).^(beta_hat-1)).*exp(-(Inum(x).^beta_hat))
ezplot(f,[0,14000])
But if I plot my function f the figure isn´t right. There should be a smooth curve, similar to the bell-shaped curve.
Does anybody recognize my fault?
採用された回答
その他の回答 (1 件)
Tiago Araujo
2021 年 6 月 24 日
I need to do a integral with a function by combining two functions, something like this:
syms q r
x(q,r) = q + 2*r;
y(q,r) = q*9 + r;
G = @(q,r) x+y
integral2(G,1,2,1,2)
It is only a example, my real problem is much more complex. How can i do that?
5 件のコメント
The only function handle you have in your code is G.
But if x and y were defined as function handles, you can't multiply function handles. What you can do is multiply the values obtained by evaluating the function handles.
x = @(q, r) q + 2*r;
y = @(q, r) 9*q + r;
G = @(q, r) x(q, r) .* y(q, r); % let's multiply rather than add
integral2(G, 1, 2, 1, 2)
Tiago Araujo
2021 年 6 月 24 日
Please, look at my real problem:
% Coordenadas no espaço X,Y,Z
P1 = [1 1 1];
P2 = [1 1 1.4];
P3 = [1.2 1 1];
P4 = [1.2 1 1.4];
P5 = [1 1.3 1];
P6 = [1 1.3 1.4];
P7 = [1.2 1.3 1];
P8 = [1.2 1.3 1.4];
% Transformação de Coordenadas
C1 = (1/8)*(1+q)*(1-r)*(1-t);
C2 = (1/8)*(1+q)*(1+r)*(1-t);
C3 = (1/8)*(1-q)*(1+r)*(1-t);
C4 = (1/8)*(1-q)*(1-r)*(1-t);
C5 = (1/8)*(1+q)*(1-r)*(1+t);
C6 = (1/8)*(1+q)*(1+r)*(1+t);
C7 = (1/8)*(1-q)*(1+r)*(1+t);
C8 = (1/8)*(1-q)*(1-r)*(1+t);
% Coordenadas em função de q,r e t
xi = C1*P1(:,1)+C2*P2(:,1)+C3*P3(:,1)+C4*P4(:,1)+...
C5*P5(:,1)+C6*P6(:,1)+C7*P7(:,1)+C8*P8(:,1);
yi = C1*P1(:,2)+C2*P2(:,2)+C3*P3(:,2)+C4*P4(:,2)+...
C5*P5(:,2)+C6*P6(:,2)+C7*P7(:,2)+C8*P8(:,2);
zi = C1*P1(:,3)+C2*P2(:,3)+C3*P3(:,3)+C4*P4(:,3)+...
C5*P5(:,3)+C6*P6(:,3)+C7*P7(:,3)+C8*P8(:,3);
% Jacobiano
J = [diff(xi,q) diff(yi,q) diff(zi,q)
diff(xi,r) diff(yi,r) diff(zi,r)
diff(xi,t) diff(yi,t) diff(zi,t)];
% Função G(q,r,t)
F = @(q,r,t) xi(q,r,t) .* yi(q,r,t)./zi(q,r,t)
G = det(J)*F
% Solução analítica
integral3(G,-1, 1, -1, 1, -1, 1)
It doesnt work.
Walter Roberson
2021 年 6 月 24 日
You have F as a function handle. You cannot multiply a function handle by anything.
You are also mixing symbolic expressions and function handles.
Stick with symbolic all the way through to creating G. Then use matlabFunction. Be sure to use the 'vars' option to control the order of variables.
Tiago Araujo
2021 年 6 月 24 日
You're great! Thanks, matlabFunction solved my problem! I didnt know this function.
James Morrison
2023 年 2 月 6 日
カテゴリ
ヘルプ センター および File Exchange で Fourier Analysis and Filtering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!