0

Debug a function plot

Hello, I am really new to Scilab and have been forced to use it for one and only one university question to graph a two functions I can graph the first function but when I try to add the second I enter something wrong. Could someone take a look at my .sce file and help point me in the right direction? clear, clf // Define your variables t1 =[0:0.01:100]; y1=25+75 ./(1+exp((t1-50)/10)); t2=[0:0.01:100]; y2 = -10 log((75/t2-25) . -1) + 50; // Use the logflag option to define logarithmic or normal axis // n for normal, l for logarithmic. plot(t1,y1,t2,y2). // Use xgrid to add a grid on your current figure xgrid; thanks Dan

Scilab

0

I've modified your code-

clear, clf // Define your variables

stacksize('max')

t1 =[0:0.01:100];

y1=25+75 ./(1+exp((t1-50)/10));

t2=[0:0.01:100];

y2 = -10 *log((75/t2-25)-1) + 50;

// Use the logflag option to define logarithmic or normal axis

// n for normal, l for logarithmic.

plot(t1,y1,t2,y2)

// Use xgrid to add a grid on your current figure

xgrid;

I've added an asterisk before log and removed the dot operator before -1.

I get a plot but there is a warning-

WARNING: Transposing row vector X to get compatible dimensions

Also, you have to increase the stacksize to max as the code exceeds the stack size allocation.

clear, clf // Define your variables

stacksize('max')

t1 =[0:0.01:100];

y1=25+75 ./(1+exp((t1-50)/10));

t2=[0:0.01:100];

y2 = -10 *log((75/t2-25)-1) + 50;

// Use the logflag option to define logarithmic or normal axis

// n for normal, l for logarithmic.

plot(t1,y1,t2,y2)

// Use xgrid to add a grid on your current figure

xgrid;

I've added an asterisk before log and removed the dot operator before -1.

I get a plot but there is a warning-

WARNING: Transposing row vector X to get compatible dimensions

Also, you have to increase the stacksize to max as the code exceeds the stack size allocation.

0

Based on y1, I get y2 to be 10 .*log(((75)./(t2-25))-1) + 50. It is different from the y2 you have calculated. I'm not sure the range you have selected is correct. When t2=100, it becomes log(0) which leads to an error. I've modified the code to this-

clc

clear

t1 =[1:10:100];

y1=25+(75)./(1+exp((t1-50)/10));

t2=[1:10:100];

g=((75)./(t2-25))-1

y2 = 10 .*log(g) + 50

plot(t1,y1,t2,y2)

xgrid;

Please check if the plot is correct now.

clc

clear

t1 =[1:10:100];

y1=25+(75)./(1+exp((t1-50)/10));

t2=[1:10:100];

g=((75)./(t2-25))-1

y2 = 10 .*log(g) + 50

plot(t1,y1,t2,y2)

xgrid;

Please check if the plot is correct now.

Hello again,

I appreciate your time and effort but unfortunately your plot still isnt quite right, I managed to make the formula work on https://www.desmos.com/calculator/u8jn3kvadi or perhaps this link will work properly http://s32.postimg.org/le7vvzdj9/Screenshot_11.png.

Im still pretty curious about how to make the formula work on sci lab

thanks

Dan

Login to add comment

0

Please check the code now-

clc

clear

t1 =[1:0.1:99.9];

y1=25+(75)./(1+exp(-(t1-50)/10));

t2=[1:0.1:99.9];

y2=zeros(size(t2,1),1)

for t=1:length(t2)

if (t2(t)==25) then // ln(0) is an error. Equate it to zero.

y2(t)=0;

else

y2(t) = -10 *(log(((75)./(t2(t)-25))-1)) + 50;

end

end

plot(t1,y1,t2,y2')

ax=gca();

ax.data_bounds=[25 25;120 120];

xgrid;

For the range you've chosen, no value exists for ln(0) and division by zero. We have to handle such exceptions in the code. Please check the plot now. y2 exists for values below t2<25.I've plotted only from t2>=25 to match the plot you have shown.

clc

clear

t1 =[1:0.1:99.9];

y1=25+(75)./(1+exp(-(t1-50)/10));

t2=[1:0.1:99.9];

y2=zeros(size(t2,1),1)

for t=1:length(t2)

if (t2(t)==25) then // ln(0) is an error. Equate it to zero.

y2(t)=0;

else

y2(t) = -10 *(log(((75)./(t2(t)-25))-1)) + 50;

end

end

plot(t1,y1,t2,y2')

ax=gca();

ax.data_bounds=[25 25;120 120];

xgrid;

For the range you've chosen, no value exists for ln(0) and division by zero. We have to handle such exceptions in the code. Please check the plot now. y2 exists for values below t2<25.I've plotted only from t2>=25 to match the plot you have shown.

25-04-16, 3:54 p.m.rinkley25-04-16, 3:55 p.m.shamika26-04-16, 2:49 p.m.rinkleyLogin to add comment