linear interpolation of function handle

조회 수: 6 (최근 30일)
Gianluca Angelini
Gianluca Angelini 2023년 11월 29일
답변: Nipun 2023년 12월 21일
Hi everybody, I need to calculate the value in the range pi <= wave_angle < pi/2 of the a function handle @(freq_wave,wave_angle) which is defined as:
((log(B/T))^-1).*(0.87/CB).^((1+Fn).*cos(wave_angle)).*(1/3-(2/3).*cos(wave_angle))
in the range ((wave_angle >=0) & (wave_angle <= pi/2))
((log(B/T))^-1).*(0.87/CB).^(1+Fn) in the range (wave_angle=pi)&(vel_nave>V_G(freq_wave)./2)&(Fn_rel(freq_wave)>=0.12)
((log(B/T))^-1).*(0.87/CB) in the range (wave_angle=pi)&(vel_nave<V_G(freq_wave)./2)+ ((log(B/T))^-1).*(0.87/CB) .*(wave_angle=pi)&(Fn_rel(freq_wave)<0.12);
but I don't konw which function is the best to use. Thanks in advance for your help.
  댓글 수: 7
Gianluca Angelini
Gianluca Angelini 2023년 11월 29일
Hi Torsten, thanks for you support. Your results are exactlay what the code do at this moment: I need to fill the empty space where the function a1 is not defined by interporlating its defintion between
((log(B/T))^-1).*(0.87/CB).^((1+Fn).*cos(wave_angle)).*(1/3-(2/3).*cos(wave_angle))
valid only for
((wave_angle >=0) & (wave_angle <= pi/2))
and
((log(B/T))^-1).*(0.87/CB).^(1+Fn) .*(vel_nave>V_G(freq_wave)./2)&(Fn_rel(freq_wave)>=0.12)) +...
((log(B/T))^-1).*(0.87/CB) .*((vel_nave<V_G(freq_wave)./2))+...
((log(B/T))^-1).*(0.87/CB) .*((Fn_rel(freq_wave)<0.12));
valid only for
(wave_angle==pi)
Torsten
Torsten 2023년 11월 29일
편집: Torsten 2023년 11월 29일
And what should be the "interpolating" function ? It's completely arbitrary at the moment.

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

답변 (1개)

Nipun
Nipun 2023년 12월 21일
Hi Gianluca,
I understand that you are trying to evaluate a semantic relation, given the variable values. In the illustrated case, the equation to be used changes according to the range of the input.
It seems like you have a piecewise function defined over different ranges of wave_angle. In MATLAB, you can use the if, elseif, and else statements to define a piecewise function. The if statements can be used to check the conditions for each range and evaluate the corresponding expression.
Here is a code snippet to help you with the same:
function result = your_function(freq_wave, wave_angle, B, T, CB, Fn, vel_nave)
if wave_angle >= 0 && wave_angle < pi/2
result = ((log(B/T))^-1) .* (0.87/CB).^((1+Fn).*cos(wave_angle)) .* (1/3 - (2/3) .* cos(wave_angle));
elseif wave_angle == pi && vel_nave > V_G(freq_wave)/2 && Fn_rel(freq_wave) >= 0.12
result = ((log(B/T))^-1) .* (0.87/CB).^(1+Fn);
elseif wave_angle == pi && vel_nave < V_G(freq_wave)/2
result = ((log(B/T))^-1) .* (0.87/CB);
elseif wave_angle == pi && Fn_rel(freq_wave) < 0.12
result = ((log(B/T))^-1) .* (0.87/CB) .* (wave_angle == pi) .* (Fn_rel(freq_wave) < 0.12);
else
% Define default behavior if none of the conditions are met
result = NaN; % or any default value you prefer
end
end
This function checks the conditions for each range of wave_angle and evaluates the corresponding expression. You can adjust the conditions and expressions based on your specific requirements. The result variable holds the final value of the function for a given set of input parameters.
Since the signature and description of functions "Fn_rel" and others were not provided, I assume that they work as expected.
Hope this helps.
Regards,
Nipun

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by