現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
integral of two added function can't be implemented
1 回表示 (過去 30 日間)
古いコメントを表示
Faisal Al-Wazir
2022 年 10 月 28 日
im trying to answer q5 here
%Q4 answer
clc
clear
u = @(t) double(t>=0);
h = @(t) exp(-t).*(u(t)-u(t-1));
h1= @(t) u(t)-2.*u(t-1)+u(t-2)
h1 = function_handle with value:
@(t)u(t)-2.*u(t-1)+u(t-2)
h2= @(t) h(t) + h1(t)
h2 = function_handle with value:
@(t)h(t)+h1(t)
fplot(h2,[-3,3])
grid on
ylim([-1 2])
% Q5 answer
clc
clear
t=@(t) t
t = function_handle with value:
@(t)t
u = @(t) double(t>=0);
h = @(t) exp(-t).*(u(t)-u(t-1));
h1= @(t) u(t)-2.*u(t-1)+u(t-2)
h1 = function_handle with value:
@(t)u(t)-2.*u(t-1)+u(t-2)
h2= @(t) h(t) + h1(t)
h2 = function_handle with value:
@(t)h(t)+h1(t)
i=integral(h2,-inf,t)
Error using integral
Limits of integration must be double or single scalars.
Limits of integration must be double or single scalars.
fplot(i,[-3,3])
grid on
ylim([-1 2])
回答 (1 件)
Paul
2022 年 10 月 28 日
Hi Faisal,
If the plot for the answer to Q4 is corret, then does the integration really need to start from -inf?
However, I suggest revisiting Q4, that solution does not look correct. Why would the output of the system be the sum of the impulse response and the input?
16 件のコメント
Faisal Al-Wazir
2022 年 10 月 29 日
ok i think i didn't understood the qustion
i did some changes to q4
can you tell me if it's correct now ?
clc
clear
u = @(t) double(t>=0);
x= @(t) u(t)-2.*u(t-1)+u(t-2)
x = function_handle with value:
@(t)u(t)-2.*u(t-1)+u(t-2)
h1 = @(t) exp(-t).*(x(t)-x(t-1));
%h2= @(t) h(t) + h1(t)
fplot(h1,[-5,5])
grid on
ylim([-1 2])
Paul
2022 年 10 月 29 日
If h1(t) is supposed to be the answer to Q4, then no, it's not correct.
Also, the expression for h in the Question isn't correct. The u(t-1) should be u(t-2).
How are you trying to solve this problem?
Faisal Al-Wazir
2022 年 10 月 30 日
yes my bad so if i change u(t-1) to u(t-2) well it be right ?
if no, then what can i do ?
clc
clear
u = @(t) double(t>=0);
h = @(t) exp(-t).*(u(t)-u(t-1));
x= @(t) u(t)-2.*u(t-1)+u(t-2)
x = function_handle with value:
@(t)u(t)-2.*u(t-1)+u(t-2)
h1 = @(t) exp(-t).*(x(t)-x(t-2));
y1=@(t) (u(t)-2.*u(t-1)+u(t-2)).* (exp(-t).*(u(t)-u(t-1))) %maybe this one is right
y1 = function_handle with value:
@(t)(u(t)-2.*u(t-1)+u(t-2)).*(exp(-t).*(u(t)-u(t-1)))
fplot(h1,[-3,3])
grid on
ylim([-1 2])
Paul
2022 年 10 月 30 日
No, just changing the u(t-1) to u(t-2) in the definition of h will not be enough. Typical approaches to solving this problem would be to use convolution or the Laplace transform.
Faisal Al-Wazir
2022 年 10 月 31 日
thanks paul but when i use conv function it gives an empty plot
clc
clear
u = @(t) double(t>=0);
h = @(t) exp(-t).*(u(t)-u(t-1));
x= @(t) u(t)-2.*u(t-1)+u(t-2)
x = function_handle with value:
@(t)u(t)-2.*u(t-1)+u(t-2)
h1= @(t) conv(h,x)
h1 = function_handle with value:
@(t)conv(h,x)
fplot(h1,[-3,3])
grid on
ylim([-1 2])
Warning: Error updating FunctionLine.
The following error was reported evaluating the function in FunctionLine update: Input arguments to function include colon operator. To input the colon character, use ':' instead.
The following error was reported evaluating the function in FunctionLine update: Input arguments to function include colon operator. To input the colon character, use ':' instead.
Paul
2022 年 10 月 31 日
Recheck the doc page for conv. The inputs are vectors of numbers, not anonymous functions as you've tried above. So you have to evaluate the functions at the values of t of interest. Also, conv computes the convolution sum, it needs to be scaled appropriately to approximate a convolution integral. Here's an example.
u = @(t) double(t >= 0); % unit step
h = @(t) exp(-2*t).*(u(t) - u(t-1)); % impulse response
x = @(t) t.*(u(t) - u(t-2)); % input
y = @(t,dt) conv(h(t),x(t))*dt; % output, scaled by dt to convert from sum to integral
tval = 0:.001:5;
dt = tval(2);
yval = y(tval,dt);
yval = yval(1:numel(tval)); % only retain as many points as in t
plot(tval,yval)
Faisal Al-Wazir
2022 年 10 月 31 日
thank you so much paul
but for q5 the same method doesn't work
%%
clc
clear
u = @(t) double(t >= 0); % unit step
h = @(t) exp(-2*t).*(u(t) - u(t-1)); % impulse response
x = @(t) t.*(u(t) - u(t-2)); % input
y = @(t,dt) conv(h(t),x(t))*dt; % output, scaled by dt to convert from sum to integral
tval = 0:.001:5;
dt = tval(2);
yval = y(tval,dt);
yval = yval(1:numel(tval)); % only retain as many points as in t
plot(tval,yval)
%%
%q5
y1=@(t) int(y,-inf,tval)
y1 = function_handle with value:
@(t)int(y,-inf,tval)
yval1 = y1(tval,dt);
Error using solution
Too many input arguments.
Too many input arguments.
yval1 = yval1(1:numel(tval));
plot(tval,yval1)
Paul
2022 年 10 月 31 日
Faisal Al-Wazir
2022 年 10 月 31 日
編集済み: Faisal Al-Wazir
2022 年 10 月 31 日
well i tried doing what you said but with no luck
and i still don't know how to add the limits (-inf to t)
%%
clc
clear
u = @(t) double(t >= 0); % unit step
h = @(t) exp(-2*t).*(u(t) - u(t-1)); % impulse response
x = @(t) t.*(u(t) - u(t-2)); % input
y = @(t,dt) conv(h(t),x(t))*dt; % output, scaled by dt to convert from sum to integral
tval = 0:.001:5;
dt = tval(2);
yval = y(tval,dt);
yval = yval(1:numel(tval)); % only retain as many points as in t
plot(tval,yval)
%%
%q5
y1= @(t) cumtrapz(y)
y1 = function_handle with value:
@(t)cumtrapz(y)
yval1 = y1(tval,dt);
Error using solution
Too many input arguments.
Too many input arguments.
yval1 = yval1(1:numel(tval));
plot(tval,yval1)
Paul
2022 年 10 月 31 日
No need to use a function handle. For example, suppose I want to integrate y(tau)*dtau from 0 to t, with y(t) equal to t^2. We know that the result should be t^3/3. Let's try it
tval = 0:.001:3;
yval = tval.^2;
plot(tval,cumtrapz(tval,yval))
Compare to closed form expression
plot(tval,tval.^3/3)
Faisal Al-Wazir
2022 年 10 月 31 日
so the final answer is this right ?
but the limits are not -inf to t
%%
clc
clear
u = @(t) double(t >= 0); % unit step
h = @(t) exp(-2*t).*(u(t) - u(t-1)); % impulse response
x = @(t) t.*(u(t) - u(t-2)); % input
y = @(t,dt) conv(h(t),x(t))*dt; % output, scaled by dt to convert from sum to integral
tval = 0:.001:5;
dt = tval(2);
yval = y(tval,dt);
yval = yval(1:numel(tval)); % only retain as many points as in t
plot(tval,yval)
%%
%q5
tval = 0:.001:3;
yval = conv(h(tval),x(tval))*dt;
yval = yval(1:numel(tval))
yval = 1×3001
1.0e+00 *
0 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002 0.0002 0.0002 0.0003 0.0003 0.0003 0.0003 0.0004 0.0004 0.0004
plot(tval,cumtrapz(tval,yval))
Paul
2022 年 10 月 31 日
Looks ok for this example, but you'll need to adapt it to the actual problem. Not sure why you recomputed tval and yval for Q5 from Q4, but it doesn't matter I suppose.
"but the limits are not -inf to t"
Yes, the effective limits are 0 to t when using cumtrapz for this problem.
From first principles, what is y(t) for t < 0? You should be able to answer this question based only on the form of h(t) and x(t). If you know the answer to this question, then you'll know the answer about the limits of integration.
Paul
2022 年 10 月 31 日
編集済み: Paul
2022 年 10 月 31 日
The impulse response is 0 for t < 0. The input to the system is 0 for t < 0. Consequently, would you expect the output of the system to be non-zero for any t < 0? If so, why? If not, then does it matter if the lower limit of integration on y(t) is -inf or 0?
Faisal Al-Wazir
2022 年 11 月 5 日
編集済み: Faisal Al-Wazir
2022 年 11 月 5 日
greetings paul
i reviewed the code that we were discussing and i think the values you were using are differnt then mine
%%
%q4
clc
clear
u = @(t) double(t >= 0); % unit step
h = @(t) exp(-t).*(u(t) - u(t-2)); % impulse response
x = @(t) u(t-1)-2*u(t-2)+u(t-3); % input
y = @(t,dt) conv(h(t),x(t))*dt; % output, scaled by dt to convert from sum to integral
tval = 0:.001:5;
dt = tval(2);
yval = y(tval,dt);
yval = yval(1:numel(tval)); % only retain as many points as in t
plot(tval,yval)
%%
%q5
tval = 0:.001:3;
yval = conv(h(tval),x(tval))*dt;
yval = yval(1:numel(tval));
plot(tval,cumtrapz(tval,yval))
Paul
2022 年 11 月 5 日
Yes, as I stated previously, I was showing an example that would have to be modified for the specific problem at hand.
Your current code changes the definition of x(t) from the original Q4. For Q5, consider extending tval to a longer time.
参考
カテゴリ
Help Center および File Exchange で Numbers and Precision についてさらに検索
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)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)