Please help me to solve error.

조회 수: 6 (최근 30일)
Harsh Pastakia
Harsh Pastakia 2023년 2월 16일
답변: Sai 2023년 3월 3일
>> u = @(t)double(t>=0);
>> h = @(t)u(t-1)-u(t-3);
>> fplot(h,[0,4])
>> title('Rectagular Pulse')
>> xlabel('Time')
>> ylabel('Amplitude');
>> grid
>> syms h func
>> F(func) = int(1*exp(1j*func*h), h, -u/2, u/2);
Unary operator '-' is not supported for operand of
type 'function_handle'.
Hi Matlab forums, hope you are all having a good day.
If anyone could spare some time to help me,I have encounted the error called "Unary operator '-' is not supported for operand of type 'function_handle' in for loop function". Does it mean I cant have a negative added onto the functional handle which calculates the drag? I have been giving a image of the specifc formula's and such I am meant to use and told not to change them, so it leads me to a problem in my code. I have tried putting brackets around the drag, so it is -1*(drag) but this does not work with or without brackets. So I'm kind of stuck where the problem is other than line 36 in which matlab tells me. I've attatched my script as a file (renamed just for clarity) and pasted it here. I've also attatched an image of all the formula's and code provided to me which should (hopefully!) assist in diagnosing my error.
I apologise if this type of question has been answered before, I did do a search on the matlab answers page and could only find one problem that was slightly similar to mine.
Any and all help is greatly appreciated forum support, thank you in advance for helping me with my problem!!
  댓글 수: 3
Harsh Pastakia
Harsh Pastakia 2023년 2월 16일
Like how??? Can you write for me.
Torsten
Torsten 2023년 2월 16일
u is a function handle depending on t that you use as limit of integration for F(func). What does that mean ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Sai
Sai 2023년 3월 3일
I understand that you wanted to perform an integration for the expression with the defined limits.
u = @(t)double(t>=0);
h = @(t)u(t-1)-u(t-3);
From the given code fragment, it can be seen that the function that handles 'u' and 'h' depends on the variable 't'.
For ‘u’, t: 0 to inf
For ‘h’ t: 1 to 3
Hence ‘u’ and ‘h’ cannot be used as integration limits.
The usage of function handles as integration limits is not permitted, hence the error.
Try running the same code with fixed limitations.
Please refer to int documentation for future reference.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by