How to plot data using the sigmoid and hyperbolic tangent functions.
Show older comments
Hello forums;
I am trying to write a MATLAB script to plot some data using a sigmoid and hyperbolic tangent function. I have been researching for so long but to no avail. If somebody could help that would be amazing! The data file and the equations are below. I have some code that has worked somewhat but it is mainly the last function I am struggling with. Anything helps!

Answers (1)
Here is your code with a few corrections.
x = xlsread('Lab 4 Data.xlsx','A2:A47')/1000;
f = xlsread('Lab 4 Data.xlsx','B2:B47')/1000;
n = length(x);
g_1 = 1;
g_2 = 1./(1+exp(-1*x));
g_1 = ones(size(x));
G=[g_1,g_2];
transG=transpose(G);
RHS=transG*f;
LHS=transG*G;
c=linsolve(LHS,RHS);
g_x=c(1)+c(2)*(1./(1+exp(-1*x)));
r=g_x-f;
R=sum(r.^2);
figure
plot(x,g_x)
hold on
plot(x,f,"*")
legend('g(x)','f data')
title('Lab 4 sigmoid Fit')
ylim([.0024 .0036])
xlim([-.2 3.5])
ft=@(x)(exp(x)-exp(-x))./(exp(x)+exp(-x));%here is the equation for hyperbolic tangent function
hold off;
plot(x,ft(x));
2 Comments
Dawson Duran
on 21 Oct 2022
x = xlsread('Lab 4 Data.xlsx','A2:A47')/1000;
ft=@(x)(exp(x)-exp(-x))./(exp(x)+exp(-x));
plot(x,ft(x));
Categories
Find more on Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

