Equation for two function curves

1 view (last 30 days)
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;

Accepted Answer

Star Strider
Star Strider on 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 Comments
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 on 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!