piecewise function and function handles
    조회 수: 3 (최근 30일)
  
       이전 댓글 표시
    
Hi everybody, I have a little trouble issues with my function handles.
In particular I am trying to describe a function handle which has a specific value (related to two variables) in a range of one of the two vairables, and 0 otherwise.
E_2rad=0.79;
@(freq_wave,wave_angle) (0<= wave_angle <= pi-E_2rad) .* ((2.25/4)*ro_w*g*B*0.75).*(sin(E_2rad+wave_angle).^2+(2.*freq_wave.*(vel_nave/g).*(cos(E_2rad).*cos(E_2rad+wave_angle)...
-cos(wave_angle)))) + (wave_angle > pi-E_2rad) .* 0
the function written as above mentioned returns a value different from 0 if wave_angle > pi-E_2rad instead and I cannot understand why and how to fix it. Thanks in advance for your help
댓글 수: 0
채택된 답변
  Dyuman Joshi
      
      
 2023년 11월 21일
        You need to define multiple conditions separately/individually i.e -  
This 
(0<= wave_angle <= pi-E_2rad)
should be - 
(wave_angle >=0) && (wave_angle <= pi-E_2rad)
댓글 수: 4
  Dyuman Joshi
      
      
 2023년 11월 21일
				
      편집: Dyuman Joshi
      
      
 2023년 11월 21일
  
			The anonymous function is vectorized and so, for the given comparison, I should have noted that it should be a single ampersand. (I really should be going to sleep earlier :P)
Nonetheless, glad to know that your issue is solved. Happy to have helped!
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!