Effacer les filtres
Effacer les filtres

Equation for two function curves

2 vues (au cours des 30 derniers jours)
Kenneth Bisgaard Cristensen
Commenté : Star Strider le 31 Mar 2021
Hi MATLAB Community,
How do I create a y using the two diffrent numbers of a,b,c,d to get two function curves. Is there anyway for the y equation to use both data sets?
Any advice would be greatly appriciated.
% DBT Curve using Tanh
a = [95.80266, 46.83612];
b = [-88.53938, 40.09957];
c = [30.84839, 10.91162];
d = [-16.56475, 33.07311];
x = linspace(-200, 150, 200);
y = arrayfun(a+b*tanh((x+c)/d));
figure;
plot(x,y);
legend('L-T', 'T-L');
legend('Location','northwest');
title('DBT Curve');
xlabel('Temperature [°C]');
ylabel('Absorved Energy [J]');
grid on;
grid minor;

Réponse acceptée

Star Strider
Star Strider le 31 Mar 2021
Try this:
a = [95.80266, 46.83612];
b = [-88.53938, 40.09957];
c = [30.84839, 10.91162];
d = [-16.56475, 33.07311];
x = linspace(-200, 150, 200);
for k = 1:numel(a)
y(k,:) = a(k)+b(k)*tanh((x+c(k))/d(k));
end
figure
plot(x, y)
grid
An explicit loop is more efficient than arrayfun.
  2 commentaires
Kenneth Bisgaard Cristensen
Hi,
Thanks that worked perfectly. It is my first year using MATLAB. I really love the commuinty, a lot of great help an suppot when you are stuck on a problem. I really appricate the help.
Star Strider
Star Strider le 31 Mar 2021
As always, my pleasure!
I was also thinking about the ± variables in your previous Question. One option would be to do something similar to what I did here, however using the parameters with what are probably the confidence intervals added and subtracted from each parameter, so the loop would repeat 16 times, once each with various combinations of the parameters with the conficence limits added or subtracted, varying one at a time and leaving the other original parameters unchanged. Then, since the result will be a matrix of row vectors, take the minimum and maximum of the matrix (along dimension 1, the row dimension) and plot those results as a function of ‘x’. Those should be the limits. That is not the most elegant solution, however it is reasonably straightforward and should give you some idea of the limits of the function with the parameter confidence intervals included.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by