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 Not Spam 25-04-16, 3:18 p.m. rinkley

Answers:

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.

Not Spam 25-04-16, 3:48 p.m. shamika

thanks for that, it looks like there might be something wrong with the equation I am using for y2.



25-04-16, 3:54 p.m. rinkley

What is the equation for y2?


25-04-16, 3:55 p.m. shamika

Well I am meant to find the inverse of the function f y1=25+75 ./(1+exp((t1-50)/10)) 

which I had calculated to be  y2 = -10 *log((75/t2-25)-1) + 50; and then plot them both.. Im pretty sure the output from scilab doesnt look quite right to how I pictured the inverse


26-04-16, 2:49 p.m. rinkley

Login to add comment


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.

Not Spam 27-04-16, 11:24 a.m. shamika

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


27-04-16, 3:41 p.m. rinkley

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.

Not Spam 28-04-16, 2:27 p.m. shamika


0

Thanks for your help, that works pretty well.

Much appreciated

Not Spam 02-05-16, 3:55 p.m. rinkley