Please help me to solve error.

2 次查看(过去 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 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by