Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Dimension mismatch in fsolve

Subject: Dimension mismatch in fsolve

From: Amjad

Date: 9 Feb, 2011 18:45:05

Message: 1 of 7

Good Day to all,
I m trying to solve some model equations defined in the file called under fsolve. Now previously, it gave me scalar or singular values (i.e., final result) but I desired results of each iteration and its subsequent plot. My coding is as follows. Everytime i try to run the program, i get "Dimnesion mismatch error" at line " s1(counter,:)=w(:,1)'; ". Can anybody help me in this regard. Secondly, what's the code for getting teh same results in excel sheet.

Thanks in advance.

Amjad

clear all
close all
clc
global Pt0 u u01 u02 u03 u04 u05 u06 u013 u015 u0 counter s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 kg hf

x0 = [0.197;0.015;0.085;0.497;0.200;0.006;0.197;0.015;0.085;0.497;0.200;0.006;880;880;1]; %initial guess for fsolve

u01=0.2278; u02=0.00157; u03=0.00768; u04=0.7279; u05=0.02796; u06=0.00729; u013=893; u015=1; %***Inlet condition*****
x0=u;

Pt0=24; % bar
delP=1.4; % bar
L=14.35; % m
delz=L/5; % m
counter=2;

tfinal=1200;
tinc=10;
tmesh=1:tinc:tfinal;

s1(1,1:length(tmesh))=0.2278;
s2(1,1:length(tmesh))=0.00157;
s3(1,1:length(tmesh))=0.00768;
s4(1,1:length(tmesh))=0.7279;
s5(1,1:length(tmesh))=0.02796;
s6(1,1:length(tmesh))=0.00729;
s7(1,1:length(tmesh))=0.2278;
s8(1,1:length(tmesh))=0.00157;
s9(1,1:length(tmesh))=0.00768;
s10(1,1:length(tmesh))=0.7279;
s11(1,1:length(tmesh))=0.02796;
s12(1,1:length(tmesh))=0.00729;
s13(1,1:length(tmesh))=893;
s14(1,1:length(tmesh))=893;
s15(1,1:length(tmesh))=1.00;


f1='Report1';
f2='Report2';
f3='Report3';
f4='Report4';
f5='Report5';
f6='Report6';
f7='Report7';
f8='Report8';
f9='Report9';
f10='Report10';
f11='Report11';
f12='Report12';
f13='Report13';
f14='Report14';
f15='Report15';

options=optimset('LargeScale','off','TolX',1e-8,'MaxIter',1e8,'MaxFunEvals',2e20);
f='ReportS';
waithandle=waitbar(0,' Step2 : ------ Steady State Simulation ------ '); % Initialize waitbar

while counter<7
    if (counter+0.01<=7),
        waitbar(counter/5,waithandle);
    end
   
    [u,fval] = fsolve(@MyfuncMSR1,x0,options);
    w(counter,:)=u';
    
    s1(counter,:)=w(:,1)';
    s2(counter,:)=w(:,2)';
    s3(counter,:)=w(:,3)';
    s4(counter,:)=w(:,4)';
    s5(counter,:)=w(:,5)';
    s6(counter,:)=w(:,6)';
    s7(counter,:)=w(:,7)';
    s8(counter,:)=w(:,8)';
    s9(counter,:)=w(:,9)';
    s10(counter,:)=w(:,10)';
    s11(counter,:)=w(:,11)';
    s12(counter,:)=w(:,12)';
    s13(counter,:)=w(:,13)';
    s14(counter,:)=w(:,14)';
    s15(counter,:)=w(:,15)';
        
    load('ReportS','w');
    a1=w(counter,1);
    a2=w(counter,2);
    a3=w(counter,3);
    a4=w(counter,4);
    a5=w(counter,5);
    a6=w(counter,6);
    a7=w(counter,7);
    a8=w(counter,8);
    a9=w(counter,9);
    a10=w(counter,10);
    a11=w(counter,11);
    a12=w(counter,12);
    a13=w(counter,13);
    a14=w(counter,14);
    a15=w(counter,15);

    u0=[a1;a2;a3;a4;a5;a6;a7;a8;a9;a10;a11;a12;a13;a14;a15];
    Pt=Pt0-(delP/L)*delz;
    counter=counter+1;
end
close(waithandle);

save(f1,'s1');
save(f2,'s2');
save(f3,'s3');
save(f4,'s4');
save(f5,'s5');
save(f6,'s6');
save(f7,'s7');
save(f8,'s8');
save(f9,'s9');
save(f10,'s10');
save(f11,'s11');
save(f12,'s12');
save(f13,'s13');
save(f14,'s14');
save(f15,'s15');
% save(f16,'s16');

bbb=clock;

% ----- 3D plotts of the model -----

figure(1);
x=1:1:6;
time=1:tinc:tfinal;
z=0:14.35/5:14.35;

figure(1);mesh(time,x,s1);title('Methane mol fraction');
figure(2);mesh(time,x,s2);title('CO2 mol fraction');
figure(3);mesh(time,x,s3);title('CO mol fraction');
figure(4);mesh(time,x,s4);title('H2O mol fraction');
figure(5);mesh(time,x,s5);title('H2 mol fraction');
figure(6);mesh(time,x,s6);title('N2 mol fraction');
figure(7);mesh(time,x,s13);title('Temperatre');
s15(1,:)=s15(2,:)
figure(8);mesh(time,x,s15);title('Activity');

Subject: Dimension mismatch in fsolve

From: Torsten Hennig

Date: 10 Feb, 2011 08:41:01

Message: 2 of 7

> Good Day to all,
> I m trying to solve some model equations defined in
> the file called under fsolve. Now previously, it gave
> me scalar or singular values (i.e., final result) but
> I desired results of each iteration and its
> subsequent plot. My coding is as follows. Everytime i
> try to run the program, i get "Dimnesion mismatch
> error" at line " s1(counter,:)=w(:,1)'; ". Can
> anybody help me in this regard. Secondly, what's the
> code for getting teh same results in excel sheet.
>
> Thanks in advance.
>
> Amjad
>
> clear all
> close all
> clc
> global Pt0 u u01 u02 u03 u04 u05 u06 u013 u015 u0
> counter s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13
> s14 s15 kg hf
>
> x0 =
> [0.197;0.015;0.085;0.497;0.200;0.006;0.197;0.015;0.085
> ;0.497;0.200;0.006;880;880;1]; %initial
> guess for fsolve
>
> u01=0.2278; u02=0.00157; u03=0.00768; u04=0.7279;
> u05=0.02796; u06=0.00729; u013=893; u015=1;
> %***Inlet condition*****
> x0=u;
>
> Pt0=24; % bar
> delP=1.4; % bar
> L=14.35; % m
> delz=L/5; % m
> counter=2;
>
> tfinal=1200;
> tinc=10;
> tmesh=1:tinc:tfinal;
>
> s1(1,1:length(tmesh))=0.2278;
> s2(1,1:length(tmesh))=0.00157;
> s3(1,1:length(tmesh))=0.00768;
> s4(1,1:length(tmesh))=0.7279;
> s5(1,1:length(tmesh))=0.02796;
> s6(1,1:length(tmesh))=0.00729;
> s7(1,1:length(tmesh))=0.2278;
> s8(1,1:length(tmesh))=0.00157;
> s9(1,1:length(tmesh))=0.00768;
> s10(1,1:length(tmesh))=0.7279;
> s11(1,1:length(tmesh))=0.02796;
> s12(1,1:length(tmesh))=0.00729;
> s13(1,1:length(tmesh))=893;
> s14(1,1:length(tmesh))=893;
> s15(1,1:length(tmesh))=1.00;
>
>
> f1='Report1';
> f2='Report2';
> f3='Report3';
> f4='Report4';
> f5='Report5';
> f6='Report6';
> f7='Report7';
> f8='Report8';
> f9='Report9';
> f10='Report10';
> f11='Report11';
> f12='Report12';
> f13='Report13';
> f14='Report14';
> f15='Report15';
>
> options=optimset('LargeScale','off','TolX',1e-8,'MaxIt
> er',1e8,'MaxFunEvals',2e20);
> f='ReportS';
> waithandle=waitbar(0,' Step2 : ------ Steady State
> Simulation ------ '); % Initialize waitbar
>
> while counter<7
> if (counter+0.01<=7),
> waitbar(counter/5,waithandle);
> end
>
> [u,fval] = fsolve(@MyfuncMSR1,x0,options);
> w(counter,:)=u';
>
> s1(counter,:)=w(:,1)';
> s2(counter,:)=w(:,2)';
> s3(counter,:)=w(:,3)';
> s4(counter,:)=w(:,4)';
> s5(counter,:)=w(:,5)';
> s6(counter,:)=w(:,6)';
> s7(counter,:)=w(:,7)';
> s8(counter,:)=w(:,8)';
> s9(counter,:)=w(:,9)';
> s10(counter,:)=w(:,10)';
> s11(counter,:)=w(:,11)';
> s12(counter,:)=w(:,12)';
> s13(counter,:)=w(:,13)';
> s14(counter,:)=w(:,14)';
> s15(counter,:)=w(:,15)';
>

I don't understand why you use two-dimensional
arrays for s1,s2,...,s15.
Setting
s1(counter)=u(1,1);
s2(counter)=u(1,2);
..
s15(counter)=u(1,15)

or better

s(counter,:)=u(1,:)

where s is a matrix of size (length(tmesh),15)

should be ok.

> load('ReportS','w');
> a1=w(counter,1);
> a2=w(counter,2);
> a3=w(counter,3);
> a4=w(counter,4);
> a5=w(counter,5);
> a6=w(counter,6);
> a7=w(counter,7);
> a8=w(counter,8);
> a9=w(counter,9);
> a10=w(counter,10);
> a11=w(counter,11);
> a12=w(counter,12);
> a13=w(counter,13);
> a14=w(counter,14);
> a15=w(counter,15);
>
>
>
>
> u0=[a1;a2;a3;a4;a5;a6;a7;a8;a9;a10;a11;a12;a13;a14;a1
> 5];
> Pt=Pt0-(delP/L)*delz;
> counter=counter+1;
> end
> close(waithandle);
>
> save(f1,'s1');
> save(f2,'s2');
> save(f3,'s3');
> save(f4,'s4');
> save(f5,'s5');
> save(f6,'s6');
> save(f7,'s7');
> save(f8,'s8');
> save(f9,'s9');
> save(f10,'s10');
> save(f11,'s11');
> save(f12,'s12');
> save(f13,'s13');
> save(f14,'s14');
> save(f15,'s15');
> % save(f16,'s16');
>
> bbb=clock;
>
> % ----- 3D plotts of the model -----
>
> figure(1);
> x=1:1:6;
> time=1:tinc:tfinal;
> z=0:14.35/5:14.35;
>
> figure(1);mesh(time,x,s1);title('Methane mol
> fraction');
> figure(2);mesh(time,x,s2);title('CO2 mol fraction');
> figure(3);mesh(time,x,s3);title('CO mol fraction');
> figure(4);mesh(time,x,s4);title('H2O mol fraction');
> figure(5);mesh(time,x,s5);title('H2 mol fraction');
> figure(6);mesh(time,x,s6);title('N2 mol fraction');
> figure(7);mesh(time,x,s13);title('Temperatre');
> s15(1,:)=s15(2,:)
> figure(8);mesh(time,x,s15);title('Activity');

Best wishes
Torsten.

Subject: Dimension mismatch in fsolve

From: Amjad

Date: 10 Feb, 2011 12:25:04

Message: 3 of 7

Thanks Torsten. I made the suggested changes, but then there was objection on dimensions of "a". So have a look at the following as I have made a few changes. Now, only problem is with plotting. Following error arises just after teh figure window opens and then I dont have any curve. :(
Error:
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using
Levenberg-Marquardt algorithm instead.
> In fsolve at 324
  In SSMSR1 at 75

Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>

??? Error using ==> mesh at 80
Z must be a matrix, not a scalar or vector.

Error in ==> SSMSR1 at 186
figure(1);mesh(time,x,s1);title('Methane mol fraction');


Revised Coding:

clear all
close all
clc
global Pt0 u u01 u02 u03 u04 u05 u06 u013 u015 u0 counter s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 kg hf

x0 = [0.197;0.015;0.085;0.497;0.200;0.006;0.197;0.015;0.085;0.497;0.200;0.006;880;880;1]; %initial guess for fsolve

u01=0.2278; u02=0.00157; u03=0.00768; u04=0.7279; u05=0.02796; u06=0.00729; u013=893; u015=1; %***Inlet condition*****

Pt0=24; % bar
delP=1.4; % bar
L=14.35; % m
delz=L/15; % m
counter=2;

tfinal=1200;
tinc=10;
tmesh=1:tinc:tfinal;
% zfinal=14.35;
% zinc=delz;
% tmesh=0:zinc:zfinal;


s1(1,1:length(tmesh))=0.2278;
s2(1,1:length(tmesh))=0.00157;
s3(1,1:length(tmesh))=0.00768;
s4(1,1:length(tmesh))=0.7279;
s5(1,1:length(tmesh))=0.02796;
s6(1,1:length(tmesh))=0.00729;
s7(1,1:length(tmesh))=0.2278;
s8(1,1:length(tmesh))=0.00157;
s9(1,1:length(tmesh))=0.00768;
s10(1,1:length(tmesh))=0.7279;
s11(1,1:length(tmesh))=0.02796;
s12(1,1:length(tmesh))=0.00729;
s13(1,1:length(tmesh))=893;
s14(1,1:length(tmesh))=893;
s15(1,1:length(tmesh))=1.00;


f1='Report1';
f2='Report2';
f3='Report3';
f4='Report4';
f5='Report5';
f6='Report6';
f7='Report7';
f8='Report8';
f9='Report9';
f10='Report10';
f11='Report11';
f12='Report12';
f13='Report13';
f14='Report14';
f15='Report15';


options=optimset('LargeScale','off','TolX',1e-8,'MaxIter',1e8,'MaxFunEvals',2e20);
f='ReportS';
waithandle=waitbar(0,' Step2 : ------ Steady State Simulation ------ '); % Initialize waitbar

while counter<17
    if (counter+0.01<=17),
        waitbar(counter/15,waithandle);
    end
   
    [u,fval] = fsolve(@MyfuncMSR1,x0,options);
    w(counter,:)=u(1,:)';
    u=x0;
% u01=w(counter,1);
% u02=w(counter,2);
% u03=w(counter,3);
% u04=w(counter,4);
% u05=w(counter,5);
% u06=w(counter,6);
% u013=w(counter,13);
% Pt0=Pt0-(delP/L)*delz;
% counter=counter+1;
% end
% save(f,'w')
%
%
% while counter<32
   
s=size(length(tmesh),15);
s(counter,:)=u(1,:);

    load('ReportS','w');
    a=size(length(tmesh),15);
    u0=[a];
    Pt=Pt0-(delP/L)*delz;
    counter=counter+1;
end
close(waithandle);

% ----- Saves the results -----

save(f1,'s1');
save(f2,'s2');
save(f3,'s3');
save(f4,'s4');
save(f5,'s5');
save(f6,'s6');
save(f7,'s7');
save(f8,'s8');
save(f9,'s9');
save(f10,'s10');
save(f11,'s11');
save(f12,'s12');
save(f13,'s13');
save(f14,'s14');
save(f15,'s15');

bbb=clock;

% ----- 3D plotts of the model -----

figure(1);
x=1:1:16;
time=1:tinc:tfinal;
z=0:14.35/15:14.35;

figure(1);mesh(time,x,s1);title('Methane mol fraction');
figure(2);mesh(time,x,s2);title('CO2 mol fraction');
figure(3);mesh(time,x,s3);title('CO mol fraction');
figure(4);mesh(time,x,s4);title('H2O mol fraction');
figure(5);mesh(time,x,s5);title('H2 mol fraction');
figure(6);mesh(time,x,s6);title('N2 mol fraction');
figure(7);mesh(time,x,s13);title('Temperatre');
s15(1,:)=s15(2,:)
figure(8);mesh(time,x,s15);title('Activity');

Subject: Dimension mismatch in fsolve

From: Torsten Hennig

Date: 10 Feb, 2011 12:41:38

Message: 4 of 7

> Thanks Torsten. I made the suggested changes, but
> then there was objection on dimensions of "a". So
> have a look at the following as I have made a few
> changes. Now, only problem is with plotting.
> Following error arises just after teh figure window
> opens and then I dont have any curve. :(
> Error:
> Warning: Trust-region-dogleg algorithm of FSOLVE
> cannot handle non-square systems; using
> Levenberg-Marquardt algorithm instead.
> > In fsolve at 324
> In SSMSR1 at 75
>
> Equation solved.
>
> fsolve completed because the vector of function
> values is near zero
> as measured by the default value of the function
> tolerance, and
> the problem appears regular as measured by the
> gradient.
>
> <stopping criteria details>
>
> ??? Error using ==> mesh at 80
> Z must be a matrix, not a scalar or vector.
>
> Error in ==> SSMSR1 at 186
> figure(1);mesh(time,x,s1);title('Methane mol
> fraction');
>
>
> Revised Coding:
>
> clear all
> close all
> clc
> global Pt0 u u01 u02 u03 u04 u05 u06 u013 u015 u0
> counter s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13
> s14 s15 kg hf
>
> x0 =
> [0.197;0.015;0.085;0.497;0.200;0.006;0.197;0.015;0.085
> ;0.497;0.200;0.006;880;880;1]; %initial
> guess for fsolve
>
> u01=0.2278; u02=0.00157; u03=0.00768; u04=0.7279;
> u05=0.02796; u06=0.00729; u013=893; u015=1;
> %***Inlet condition*****
>
> Pt0=24; % bar
> delP=1.4; % bar
> L=14.35; % m
> delz=L/15; % m
> counter=2;
>
> tfinal=1200;
> tinc=10;
> tmesh=1:tinc:tfinal;
> % zfinal=14.35;
> % zinc=delz;
> % tmesh=0:zinc:zfinal;
>
>
> s1(1,1:length(tmesh))=0.2278;
> s2(1,1:length(tmesh))=0.00157;
> s3(1,1:length(tmesh))=0.00768;
> s4(1,1:length(tmesh))=0.7279;
> s5(1,1:length(tmesh))=0.02796;
> s6(1,1:length(tmesh))=0.00729;
> s7(1,1:length(tmesh))=0.2278;
> s8(1,1:length(tmesh))=0.00157;
> s9(1,1:length(tmesh))=0.00768;
> s10(1,1:length(tmesh))=0.7279;
> s11(1,1:length(tmesh))=0.02796;
> s12(1,1:length(tmesh))=0.00729;
> s13(1,1:length(tmesh))=893;
> s14(1,1:length(tmesh))=893;
> s15(1,1:length(tmesh))=1.00;
>
>

The s_i are no longer necesssary.
Allocate s here and set its first row to x0:
s=zeros(length(tmesh),15);
s(1,:) = x0(1,:);

> f1='Report1';
> f2='Report2';
> f3='Report3';
> f4='Report4';
> f5='Report5';
> f6='Report6';
> f7='Report7';
> f8='Report8';
> f9='Report9';
> f10='Report10';
> f11='Report11';
> f12='Report12';
> f13='Report13';
> f14='Report14';
> f15='Report15';
>
>
> options=optimset('LargeScale','off','TolX',1e-8,'MaxIt
> er',1e8,'MaxFunEvals',2e20);
> f='ReportS';
> waithandle=waitbar(0,' Step2 : ------ Steady State
> Simulation ------ '); % Initialize waitbar
>
> while counter<17
> if (counter+0.01<=17),
> waitbar(counter/15,waithandle);
> end
>
> [u,fval] = fsolve(@MyfuncMSR1,x0,options);
> w(counter,:)=u(1,:)';
> u=x0;

Why do you reset u to its initial guess here ?

> % u01=w(counter,1);
> % u02=w(counter,2);
> % u03=w(counter,3);
> % u04=w(counter,4);
> % u05=w(counter,5);
> % u06=w(counter,6);
> % u013=w(counter,13);
> % Pt0=Pt0-(delP/L)*delz;
> % counter=counter+1;
> % end
> % save(f,'w')
> %
> %
> % while counter<32
>
> s=size(length(tmesh),15);
> s(counter,:)=u(1,:);
>
> load('ReportS','w');
> a=size(length(tmesh),15);
> u0=[a];
> Pt=Pt0-(delP/L)*delz;
> counter=counter+1;
> end
> close(waithandle);
>
> % ----- Saves the results -----
>
> save(f1,'s1');
> save(f2,'s2');
> save(f3,'s3');
> save(f4,'s4');
> save(f5,'s5');
> save(f6,'s6');
> save(f7,'s7');
> save(f8,'s8');
> save(f9,'s9');
> save(f10,'s10');
> save(f11,'s11');
> save(f12,'s12');
> save(f13,'s13');
> save(f14,'s14');
> save(f15,'s15');
>
> bbb=clock;
>
> % ----- 3D plotts of the model -----
>
> figure(1);
> x=1:1:16;
> time=1:tinc:tfinal;
> z=0:14.35/15:14.35;
>
> figure(1);mesh(time,x,s1);title('Methane mol
> fraction');
> figure(2);mesh(time,x,s2);title('CO2 mol fraction');
> figure(3);mesh(time,x,s3);title('CO mol fraction');
> figure(4);mesh(time,x,s4);title('H2O mol fraction');
> figure(5);mesh(time,x,s5);title('H2 mol fraction');
> figure(6);mesh(time,x,s6);title('N2 mol fraction');
> figure(7);mesh(time,x,s13);title('Temperatre');
> s15(1,:)=s15(2,:)
> figure(8);mesh(time,x,s15);title('Activity');

Best wishes
Torsten.

Subject: Dimension mismatch in fsolve

From: Amjad

Date: 10 Feb, 2011 13:48:05

Message: 5 of 7

Well.... things seem to getting settled..as I followed on to your advice. n this time got this msg:

Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using
Levenberg-Marquardt algorithm instead.
> In fsolve at 324
  In SSMSR1 at 77

Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>

??? Error using ==> mesh at 80
Data dimensions must agree.

Error in ==> SSMSR1 at 188
figure(1);mesh(time,x,s1);title('Methane mol fraction');

Thanks,
Amjad

Subject: Dimension mismatch in fsolve

From: Torsten Hennig

Date: 10 Feb, 2011 15:00:15

Message: 6 of 7

> Well.... things seem to getting settled..as I
> followed on to your advice. n this time got this msg:
>
> Warning: Trust-region-dogleg algorithm of FSOLVE
> cannot handle non-square systems; using
> Levenberg-Marquardt algorithm instead.
> > In fsolve at 324
> In SSMSR1 at 77
>
> Equation solved.
>
> fsolve completed because the vector of function
> values is near zero
> as measured by the default value of the function
> tolerance, and
> the problem appears regular as measured by the
> gradient.
>
> <stopping criteria details>
>
> ??? Error using ==> mesh at 80
> Data dimensions must agree.
>
> Error in ==> SSMSR1 at 188
> figure(1);mesh(time,x,s1);title('Methane mol
> fraction');
>
> Thanks,
> Amjad

Please include the actual code.

As far as I can see, with each call to fsolve you
will get the same solution for u since Pt is
the only variable that is changed within the
while loop, but it is not declared as a global variable.

Best wishes
Torsten.

Subject: Dimension mismatch in fsolve

From: Amjad

Date: 10 Feb, 2011 15:49:05

Message: 7 of 7

You are right in the sense that only the value of Pt is varying but the value of u is totally dependent on Pt and so it will change at every loop. The equations for different values of u are defined in Myfunc file. Like i mentioned earlier, initially, i wrote this program for a single set of values as a solution to the system of equations, but now want a graphical representation of the gradual change in the values of u. So every iteration result shall be a point on the curve.

Thanks,
Amjad

clear all
close all
clc
global Pt0 u u01 u02 u03 u04 u05 u06 u013 u015 u0 counter s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 kg hf

x0 = [0.197;0.015;0.085;0.497;0.200;0.006;0.197;0.015;0.085;0.497;0.200;0.006;880;880;1]; %initial guess for fsolve

u01=0.2278; u02=0.00157; u03=0.00768; u04=0.7279; u05=0.02796; u06=0.00729; u013=893; u015=1; %***Inlet condition*****

Pt0=24; % bar
delP=1.4; % bar
L=14.35; % m
delz=L/15; % m
counter=2;
tfinal=1200;
tinc=10;
tmesh=1:tinc:tfinal;

s=zeros(length(tmesh),15);
s(1,:) = x0(1,:);

f1='Report1';
f2='Report2';
f3='Report3';
f4='Report4';
f5='Report5';
f6='Report6';
f7='Report7';
f8='Report8';
f9='Report9';
f10='Report10';
f11='Report11';
f12='Report12';
f13='Report13';
f14='Report14';
f15='Report15';

options=optimset('LargeScale','off','TolX',1e-8,'MaxIter',1e8,'MaxFunEvals',2e20);
f='ReportS';
waithandle=waitbar(0,' Step2 : ------ Steady State Simulation ------ '); % Initialize waitbar

while counter<17
    if (counter+0.01<=17),
        waitbar(counter/15,waithandle);
    end
   
    [u,fval] = fsolve(@MyfuncMSR1,x0,options);
    w(counter,:)=u(1,:)';
  load('ReportS','w');
    a=size(length(tmesh),15);
   u0=[a];
    Pt=Pt0-(delP/L)*delz;
    counter=counter+1;
end
close(waithandle);

save(f1,'s1');
save(f2,'s2');
save(f3,'s3');
save(f4,'s4');
save(f5,'s5');
save(f6,'s6');
save(f7,'s7');
save(f8,'s8');
save(f9,'s9');
save(f10,'s10');
save(f11,'s11');
save(f12,'s12');
save(f13,'s13');
save(f14,'s14');
save(f15,'s15');

bbb=clock;

figure(1);
x=1:1:16;
time=1:tinc:tfinal;
z=0:14.35/15:14.35;

figure(1);mesh(time,x,s1);title('Methane mol fraction');
figure(2);mesh(time,x,s2);title('CO2 mol fraction');
figure(3);mesh(time,x,s3);title('CO mol fraction');
figure(4);mesh(time,x,s4);title('H2O mol fraction');
figure(5);mesh(time,x,s5);title('H2 mol fraction');
figure(6);mesh(time,x,s6);title('N2 mol fraction');
figure(7);mesh(time,x,s13);title('Temperatre');
s15(1,:)=s15(2,:)
figure(8);mesh(time,x,s15);title('Activity');
---------------------------------------------------------



Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <198293967.72310.1297350045774.JavaMail.root@gallium.mathforum.org>...
> > Well.... things seem to getting settled..as I
> > followed on to your advice. n this time got this msg:
> >
> > Warning: Trust-region-dogleg algorithm of FSOLVE
> > cannot handle non-square systems; using
> > Levenberg-Marquardt algorithm instead.
> > > In fsolve at 324
> > In SSMSR1 at 77
> >
> > Equation solved.
> >
> > fsolve completed because the vector of function
> > values is near zero
> > as measured by the default value of the function
> > tolerance, and
> > the problem appears regular as measured by the
> > gradient.
> >
> > <stopping criteria details>
> >
> > ??? Error using ==> mesh at 80
> > Data dimensions must agree.
> >
> > Error in ==> SSMSR1 at 188
> > figure(1);mesh(time,x,s1);title('Methane mol
> > fraction');
> >
> > Thanks,
> > Amjad
>
> Please include the actual code.
>
> As far as I can see, with each call to fsolve you
> will get the same solution for u since Pt is
> the only variable that is changed within the
> while loop, but it is not declared as a global variable.
>
> Best wishes
> Torsten.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us