[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: matlab lsqnonlin equivalent in octave but with only two parameters a
From: |
HarryGeorgou |
Subject: |
Re: matlab lsqnonlin equivalent in octave but with only two parameters and Global Variable issue in a function i found |
Date: |
Mon, 16 Feb 2015 02:10:49 -0800 (PST) |
I often run pkg load all which loads among others the optim package and in
the src directory where the other packages are is an .m file that needs to
be run to install them. I did that, although others might not
realise so it is good to mention it.
I kind of just thought someone might be curious like me to look into what I
have done so thought I would provide the relevant information.
I think I have solved a bit of my problems with advice from some friends,
from a function originally as written in the previous post.
I changed it to this:
function y = myfunc_b0_1(b0)
#[FNAME_Func, FPATH_func, FLTIDX_Func] = uigetfile ('This is to select
the function so that it is in the load path');
#Fid_func = fopen(FNAME_Func);
global V;
global I;
global Voc;
global Isc;
global T;
global kB;
global q;
VAL1=(Isc-(Voc-b0(2)*Isc)/b0(3))
VAL1a = -q*Voc/(b0(1) *kB*T)
VAL2=exp(-q*Voc/(b0(1) *kB*T))
VAL2a=exp(-329)
VAL2b=exp(-0.22)
VAL3=b0(3)*q*(b0(2)*(Isc+b0(2)*Isc/b0(3))+V)/b0(1)/kB/T/(b0(3)+b0(2))
Icalshort=
Ical=-(-q.*V+(-lambertw(q*b0(2)*VAL1*VAL2a*VAL2b*b0(3)/(b0(2)*b0(1)*kB*T+b0(3)*b0(1)*kB*T)*exp(VAL3))+b0(3)*q*(b0(2)
*(Isc+b0(2)*Isc/b0(3))+V)/b0(1)/kB/T/(b0(3)+b0(2)))*b0(1)*kB*T)/q/b0(2);
y=Icalshort-I
This helps me see if and what is going on.
my call to the function is this
global I
global V
global Isc = current(1)
global Isc = 0.031085
global Voc = -0.75180
global Voc = voltage(VocPos)
#temperature degrees
#Voc = -0.7518
global T = 26.5 # the eqn in func does not work below 26.5 need to find
out a better way
q = -1.6021765e-19
global kB = 1.3806488e-23
#Initial values of n0, Rs0, Rsh0
b0=[n0, Rs0, Rsh0]'
b0=[1, 1, Rsh0] I put these values to help the function not to produce
errors otherwise I exceed realmax/realmin in the function.
b= fsolve('myfunc_b0_1',b0)
#in matlab this is b = nonlinsq('myfunc' or 'myfunc_b0_1', b0)
with further work that I have done asking people, not sure exactly but good
thing is the program kind of works.
For those who ask if you can use fsolve and nonlinsq in the same way i.e.
nonlinsq(func, initial conditions) I think they can be as I am doing that
now.
By themselves from the variables produce values
BUT I am running into a problem still.
When I call fsolve to run the function and solve it gives me this:
VAL1 = 0.035903
VAL1a = [](0x0)
VAL2 = [](0x0)
VAL2a = 1.3095e-143
VAL2b = 0.80252
error: myfunc_b0_1: operator *: nonconformant arguments (op1 is
0x0, op2 is 255x1)
error: called from:
error: C:\Users\user\Documents\Destiny\ADCModules\myfunc_b0_1
.m at line 44, column 5
error: C:\Octave\Octave-3.8.2\share\octave\3.8.2\m\optimizati
on\fsolve.m at line 201, column 8
referring to this line in fsolve:
## Initial evaluation.
## Handle arbitrary shapes of x and f and remember them.
fvec = fcn (reshape (x, xsiz));
...
My curiosity is how my variables cause [] (0x0)
while calculating values and inputting them seperately in without fsolve
gives numbers.
I will try to find out why the other function did not work and had
global variables but since i have made part of it work i'm trying to
move on.
ps. my data columns are 255 columns in length so i am not sure if it is
desired for me to put them up here.
lets say it ranges
V= -0.0019836 : -0.50583, equally space at (0.0019836) between each value
I = 0.031085 : 0.026974 with a curve in the shape of a gentle slope
--
View this message in context:
http://octave.1599824.n4.nabble.com/matlab-lsqnonlin-equivalent-in-octave-but-with-only-two-parameters-and-Global-Variable-issue-in-a-fud-tp4668545p4668609.html
Sent from the Octave - General mailing list archive at Nabble.com.