Smooth decay of a function
Mostrar comentarios más antiguos
I have a function which dies of quickely. I need this function to smoothly decay off to 0 . Is there any way in Matlab to make that happen?
4 comentarios
Alan Stevens
el 26 de Jul. de 2020
What's the function?
Saurav
el 26 de Jul. de 2020
Image Analyst
el 26 de Jul. de 2020
Please give values for everything in that alphabet soup. And include a screenshot of what you got, and what you'd like to achieve, but only after you read this link.
T = linspace(-5, 5, 500);
Tc = 3;
y = 2;
a = 7;
b = 6;
m = ((-b + (((b*b)-(4*y*a*(T-Tc))).^0.5))/(2*y)).^0.5;
subplot(2, 1, 1);
plot(T, real(m), 'b-', 'LineWidth', 2);
title('Real(m) vs. T', 'FontSize', 20);
grid on;
xlabel('T', 'FontSize', 20);
ylabel('real(m)', 'FontSize', 20);
% For T>Tc, m(T) becomes complex so m(T>Tc)=0
% Hence I want m(T) to smoothly decay to 0 for T>Tc
subplot(2, 1, 2);
plot(T, imag(m), 'b-', 'LineWidth', 2);
title('Imag(m) vs. T', 'FontSize', 20);
grid on;
xlabel('T', 'FontSize', 20);
ylabel('imag(m)', 'FontSize', 20);

For the random values I chose, it does look like the curve approaches the Tc point smoothly. What does it look like for you, with your values???
Saurav
el 27 de Jul. de 2020
Respuestas (1)
Alan Stevens
el 26 de Jul. de 2020
Editada: Alan Stevens
el 26 de Jul. de 2020
How about writing a function like:
function mfn = mvalue(T,Tc,a,b,y)
disc = b^2 - 4*y*a*(T - Tc);
quad = -b + disc^0.5/(2*y);
if disc>0 && quad>0
mfn = quad^0.5;
else
mfn = 0;
end
end
and then calling
m(i) = mvalue(T(i), Tc, a, b, y);
5 comentarios
Saurav
el 26 de Jul. de 2020
Alan Stevens
el 26 de Jul. de 2020
The value of m could be complex before T reaches Tc (if quad is negative). The mvalue function simply returns zero whenever it would otherwise have returned a compex number.
Saurav
el 26 de Jul. de 2020
Alan Stevens
el 26 de Jul. de 2020
Editada: Alan Stevens
el 26 de Jul. de 2020
Impossible to tell without knowing about the system you are modelling. Mathematically you could probably multiply m by some sort of exponential decay term. However, would that make sense in the context of your model?
Saurav
el 27 de Jul. de 2020
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!