How to get numerical values of nonlinear implicit function?

4 visualizaciones (últimos 30 días)
Romio
Romio el 19 de Mzo. de 2023
Editada: John D'Errico el 19 de Mzo. de 2023
I plotted the following implicit function
k = -1.5
F = @(t,y) log(abs(y)) - y^2/2 - t - k;
fimplicit(F,[0,2],'*')
How do I get the numerical values for every t between 0 and 1, for the function value greater than or equal to y = 1 (the upper part half of the hyperbole)?

Respuesta aceptada

Torsten
Torsten el 19 de Mzo. de 2023
Editada: Torsten el 19 de Mzo. de 2023
k = -1.5;
F = @(t,y) log(abs(y)) - y.^2/2 - t - k;
fimplicit(F,[0,4],'*')
t = 0:0.01:0.99;
y0 = 2.0;
y = zeros(size(t));
for i = 1:numel(t)
y(i) = fzero(@(y)F(t(i),y),y0);
y0 = y(i);
end
plot(t,y)

Más respuestas (1)

John D'Errico
John D'Errico el 19 de Mzo. de 2023
Editada: John D'Errico el 19 de Mzo. de 2023
This is far easier then you may think. Um, trivially so. Just solve for t, as a function of y. Pencil and paper suffice for that. But if you prefer, we can use MATLAB to do the complicated work.
syms t y
k = -1.5;
tsol = solve(log(abs(y)) - y^2/2 - t - k,t)
tsol = 
Yeah, I know, that was complicated. WHEW! You can see it is symmetric as a function of y. negative values of y will yield the same result due to the abs and y^2.
fplot(tsol,[0,5])
xlabel y
ylabel t
grid on
y = (0:0.25:5)';
tfun = matlabFunction(tsol)
tfun = function_handle with value:
@(y)log(abs(y))-y.^2./2.0+3.0./2.0
t_y = tfun(y);
table(y,t_y)
ans = 21×2 table
y t_y ____ ________ 0 -Inf 0.25 0.082456 0.5 0.68185 0.75 0.93107 1 1 1.25 0.94189 1.5 0.78047 1.75 0.52837 2 0.19315 2.25 -0.22032 2.5 -0.70871 2.75 -1.2696 3 -1.9014 3.25 -2.6026 3.5 -3.3722 3.75 -4.2095
Not unexpectedly, undefined at y==0, but very simply solved.
To go the other way, you need to recognize there are two solutions for every possible value of t. So that relationship is not single valued. If you allow negative solutions for y, then there are four solutions for any value of t.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by