How to obtain argument value of an equation
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
moh mor
el 12 de Abr. de 2023
Comentada: moh mor
el 12 de Abr. de 2023
Hello, I want to know for what values of x, f(x) is equal to half of its max value. I want to use value of this argument in my future computation in MATLAB. How can I do this in MATLAB?
2 comentarios
Sam Chak
el 12 de Abr. de 2023
Hi @moh mor
Can you define the meaning of "half of its max value"?
x = linspace(0, 10, 1001);
f = 1*sin(pi/5*x) - 1*tanh(2.3*(x - 5)) + 8;
plot(x, f, 'linewidth', 1.5), grid on, ylim([0 12])
halfmax = max(f)/2
yline(max(f), '--', 'max');
yline(halfmax, '--', 'halfmax');
Respuesta aceptada
John D'Errico
el 12 de Abr. de 2023
Editada: John D'Errico
el 12 de Abr. de 2023
I wrote an allcrossings tool, that I posted on the file exchange. I've attached it here.
help allcrossings
For example, consider the function
fun = @(x) abs(x).^1.5./(1 + (x-1.23).^2);
fplot(fun,[-10,10])
grid on
hold on
Assume we are willing to search over the interval in x of [-10,10]. (I know this function approaches zero asymptotically as x goes to infinity in either direction. So I need not worry about any other peaks.)
First, find the peak value.
[xmax,fmax] = fminbnd(@(x) -fun(x),-10,10);
xmax
fmax = -fmax
So the peak value lies around 1.7786, and the peak itself is 1.823...
Now we find the two points where the function attains the value at half the peak.
xcross = allcrossings(fun,fmax/2,[-10,10],1000)
xline(xcross,'r')
yline(fmax/2,'g')
So the two points where the function attains half the peak height.
Más respuestas (1)
Vilém Frynta
el 12 de Abr. de 2023
My approach:
f = @(x) x^2; % function example
[max_val, max_idx] = fminbnd(@(x) -f(x), -10, 10); % find maximum value of the f
half_max_val = max_val/2; % divide maximum by two
1 comentario
John D'Errico
el 12 de Abr. de 2023
Editada: John D'Errico
el 12 de Abr. de 2023
NO. You misunderstood the question. The question was NOT to compute the maximum value, and then divide by 2.
The question was to locate the point x, where the function attains half that maximum value. While you did learn the maximum, you did not solve the real problem.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!