Equation for two function curves

2 次查看(过去 30 天)
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;

采纳的回答

Star Strider
Star Strider 2021-3-31
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 个评论
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 2021-3-31
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by