snuka00 0 Newbie Poster

Hi...I'm very new to Matlab, I need urgent with a program of mine. Can anyone please help me?? thanks a million.

The following is the error message I get everytime I run program 1:

??? Error using ==> optimset
Expected argument 2 to be a string parameter name or an options structure
created with OPTIMSET.

Error in ==> C:\MATLAB_SE_5.3\toolbox\matlab\funfun\fminsearch.m
On line 58 ==> options = optimset(defaultopt,options);

Error in ==> C:\MATLAB_SE_5.3\work\uptake_main.m
On line 144 ==> [Drr_opt,options] = fminsearch('residual3',0,1,options,exp_data); %single parameter optim

-------------------------------------------------------------------

I have 3 separate programs linked.
The following are samples of my programs:


--------------------------- Program 1 -----------------------------------


clear all; clc; format short e; %clear the memory and screen

global T_temp V_batch W_sample p0 Cu0 Cu_inf residual3 %global parameters for other subroutines

%--------- 1. Experiment kinetics data has 2 column / or isotherm data
% [time,pressure_reading]

exp_data=[10 129.97
20 129.62
30 129.28
40 128.93
50 128.59
60 128.59
70 128.59
100 127.90
130 127.90
160 127.55
200 127.55
230 127.21
260 126.86
300 126.52
420 126.17
540 125.48
660 124.80
780 124.11
900 123.42
1020 123.07
1140 122.38
1260 122.04
1380 121.35
1500 121.00
1620 120.31
1740 119.97
1860 119.62
1980 118.93
2100 118.59
2220 118.25
2340 117.90
2460 117.56
2580 116.87
2700 116.52
2820 116.18
2940 115.83
3060 115.49
3180 115.14
3300 114.80
3420 114.45
3540 114.11
3660 113.76
3780 113.42
3900 113.07
4020 112.73
4140 112.38
4260 112.04
4380 111.70
4500 111.70
4620 111.35
4740 111.01
4860 110.66
4980 110.66
5100 110.32
5220 109.97
5340 109.63
5460 109.63
5580 109.28
5700 108.94];

%---------2.the parameter of the adsorber--------------------%
T_temp = 297 ; %temperature, K
V_batch = 320 ; %volume of adsorber, cc
W_sample = 2.64; %weight of sample, g


%-------------3. The parameter of the adsorption isotherm------------------%

b = 9.7618e-002; %Langmuir isotherm, b 1/kPa
Cus = 4.2992e+000; %Langmuir Cus, mmol/g


pl0 = 12.7; %max(exp_data(:,2)); %previous points, kPa
p0 = max(exp_data(:,2)); %first point for this run

pf = min(exp_data(:,2)); %final pressure, kPa
pp = [pl0,pf], %the initial and final pressure

Cu = Cus.*b.*pp./(1+b.*pp) , %[Cu0, Cu_inf] langmuir isotherm for initial and final adsorbed concentration
Cu0 = Cu(1); Cu_inf = Cu(2);

%-------------4. the initial guess, good initial guess ensures the convergency---------%

a0 = input('Input the initial value of the diffusion time constant 1/s :');
figure(1); k=1;

while k == 1;

y_model = uptake_kinetics(a0,exp_data);

plot(exp_data(:,1),exp_data(:,2),'o',exp_data(:,1),y_model);

iyes=input('Change the initial input of Drr (Y/N) = ','s');

if iyes=='y' | iyes=='yes' | iyes=='Y' | iyes=='Yes'

a0=input('initial value of Drr : ');

else
k=0;
end
end

%---------5. Start the optimisation-------------%

disp(date);
disp('*********Running Program**********');


options = []; %using default value for optim

[Drr_opt,options] = fminsearch('residual3',0,1,options,exp_data); %single parameter optim

[Drr_opt,options] = fminsearch('residual3',a0,options,[],exp_data); %multi-parameter optim


%----------------6. Display the optimization setup----------------%

disp(option(1:6)); disp(options(7:12)); disp(options(13:18));

%----------------7. Plot the experimental data and theoretical curve------------%

t_min = 0; t_max = max(exp_data(:,1)); %limits of x-axis

x_plot = linspace(0,t_max,100)'; %take 100 points for x-axis
y_plot = uptake_kinetics(Drr_opt,x_plot); %calculate the theoretical function value for x-axis

plot(exp_data(:,1),exp_data(:,2),'o',x_plot,y_plot');
plot_data = [x_plot,y_plot]; %convert the theoretical data to a matrix

disp('The optimal diffusion constant is: ');
disp(Drr_opt);


----------------------------Program 2----------------------------------


global T_temp V_batch W_sample p0 Cu0 Cu_inf residual3 %global parameters for other subroutines


indicator = 2; %set indicator = 1 to calculate equilibrium

if indicator == 2; %calculate kinetics;

t = exp_data(:,1);

ll = length(t);

for j = 1:ll;

sum(j) = 0;
sum2(j) = 10000;

for i = 1:1e+6
sum(j) = sum(j) + 1./i.^2.*exp(-Drr.*i.^2.*pi.^2.*t(j));

if abs((sum2(j)-sum(j))./sum2(j))<0.001
break;

elseif sum(j)<1e-40
break;
else
sum2(j) = sum(j);
end

end

yy(j) = 1-6/pi.^2.*sum(j); %inside particle

y(j) = p0 - 3.16.*8.31.*T_temp./V_batch.*(Cu_inf - Cu0).*yy(j); %y(j)=0


end

%end;


disp(y)

else %calculate equilibrium

p = exp_data(:,1);
b=Drr(1); Cus = Drr(2);
y = Cus.*b*p./(1+b.*p); %Langmuir isotherm

end;


if size(y,1) == 1; %to ensure the data column-wise
y = y'
end


----------------------Program 3------------------------------------

global T_temp V_batch W_sample p0 Cu0 Cu_inf residual3 %global parameters for other subroutines

y = residual3(a0,exp_data)

y_exp = exp_data(:,2);

y_the = uptake_kinetics(a0,exp_data);

y = sum((y_exp-y_the)^2);


-----------------------------------------------------------------

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.