Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need help, getting [empty sym] with solve function

MechIrTueMechIrTue Member Posts: 2
Hey everybody out there, I've been working on a script for a while now and I just can't get it to work, since I need to use the solve function.
The problem now is that it gives me the whole time an [empty sym] value while in fact I need a numerical value.

I've already tried, fsolve, fzero, and even took a look at the bisection method but that seemed to complex and more importantly would take to long.

So I'm asking if somebody could take a look at my file and teel me what I did wrong and how I could solve it.

There are a lot of comments in dutch, which just merely state what some symbols mean and why I put that code there, since it's for a project that I'm working on with other people (they don't know how to solve it either).

Code:
[code]%Geheugen wissen
clear all

@progressbar.m
clc
n = 0.3;
progressbar('tot', 'acyc', 'Riproces','Omegaduur') % Create figure and set starting time
%Variabelen

%Variabelen invoeren

optdp100=0;
optdPfilter=500;
omegahoogste=0;

%Volumestroom(<(300/3600))
Q = 300/3600;
%Lengte kanaal(0.250<Lc<0.300)
Lc = 0.2;
%Diameter kanaal
diametercmin = 1e-3; %kleinste
diametercmax = 10e-3; %grootste
%Reductie in het doorstroomd oppervlak
e = 0.1;
%Buitenstraal filterelement(<0.100)
Ro = 0.1;
%Binnenstraal filterelement
Ri = (2/5)*Ro;
%Dichtheid vervuiling
Dichtheidp = 2000;
%Dichtheid lucht
Dichtheids = 1.188;
%Viscositeit lucht
viscositeit = 18e-6;
%Hoek van de schoepen in de swirler
amin = 10; %kleinste
amax = 80; %grootste

%drukval swirler
%dPswirler = ?;

%totale drukval(moet < 500)
%dPtotaal = dPswirler + dPfilter + dPpreseperator +dP postseparator


%Loops
for diameterc = diametercmin:2.5e-4:diametercmax % diameter kanaal
progressbar([],0)
for a = amin:5:amax %hoek stap groote in graden
progressbar([],[],0)
for Riswirl = Ri+0.05:0.05:Ro %binnen diameter swirl
%for Omega = 0:1:500 %dit was gebruikt toen we nog geen formule
%voor Omega hadden

%Hoek van de schoepen in de swirler
alpha = a*2*pi/360;

%Frontaal oppervlakte filter
A = pi*(Ro^2-Ri^2)*(1-e);
%Frontaal oppervlakte swirler(aannemende dat we de Ro en Ri hetzelfde
%kiezen)
A2 = pi*(Ro^2-Riswirl^2);
%Stroomsnelheid door filter
Vg = Q/A;
%Axiale stroomsnelheid door swirler
Vg2 = Q/A2;

syms Omega1 %variabele invoeren zodat matlba niet gaat zeuren bij de volgende formules
Gswirl=((2*viscositeit*tan(alpha)*Q^2)*(Ro^3 - Riswirl^3))/(3*pi*(Ro^2 - Riswirl^2)^2); % impulsmoment swirl
Gfe=(3*Dichtheids*Omega1*Q*(Ro^5-Ri^5))/(5*(Ro^3-Ri^3)); % impulsmoment filter element
veiligheidsfactor=0.9; % veiligheids factor voor deeltjes grote tov dc
Lpre=(81*viscositeit*(Vg+Vg2)*(Riswirl-Ri)*Ri^3*(Ro-Ri)^2)/((veiligheidsfactor*diameterc)^2*(Dichtheidp-Dichtheids)*Omega1^2*(Ro^3-Ri^3)^2); %lengte die de pre separator moet krijgen om de juiste orde deeltje te filteren
Gpre=Gswirl*(1-10^(-0.01695*(Lpre/(2*Ro))^0.8)); % impulsmoment preseparator
SomG=(Gswirl-Gfe-Gpre); % gebruikt voor de volgende controle, somatie van de impulsmomenten
symvar(SomG) % dit laat zien welke variable er in SomG zitten en is alleen bedoeld ter controle om te kijken of alles behalve Omega1 ook wel echt een warde heeft
Omega=solve('Gswirl-Gfe-Gpre=0', 'Omega1') % hier moet eigenlijk een ; achter maar die staat er nu even niet om te zien of Omega een goede waarde krijgt

%De code die hier staat had ik gebruikt omdat ik eerst dacht er een
%symbolische waarde uitkwam bij de solve functie (toen had ik Omega
%ook Omegamatrix genoemt. Deze Omegatrix gaf toen een matrix en
%deze code heb ik toen gebruikt om de variabelen in de matrix af te
%gaan, maar na goed kijken bleek dat de waardes in deze matrix niet
%ander dan fout konden zijn omdat ze totaal niet veranderde als de
%variabelen werden verandert.
%Omegamatrix=double('Omegamatrix');
%[m,n]=size(Omegamatrix);
%progressbar([],[],[],0)
%for stap = 1:1:n
% Omega=Omegamatrix(1,stap);
if (Omega>omegahoogste) % ook een simpele nacontrole
omegahoogste=Omega;
end

%Grootte van deeltjes die wordt afgevangen 100% (in ideale situatie, Q
%evenredig met straal)(=3e-6)
dp100 = sqrt((27*viscositeit*Q*diameterc)/((Dichtheidp-Dichtheids)*Omega^2*Lc*(1-e)*pi*(Ro^3-Ri^3)));

%drukval
dPfilter = ((53.12*viscositeit*Lc)/(Dichtheids*Vg*((1/3)*sqrt(3)*diameterc))+1.16)*.5*Dichtheids*Vg^2;

%Assnelheid Reax moet < 2000
Reax = (Dichtheids*Vg*diameterc)/viscositeit;
%Hoeksnelheid Reomega < 108
Reomega = (Dichtheids*Omega*diameterc^2)/viscositeit;
if ((Reax <= 2000 && Reomega <= 108)||(Reax <= 166)) % gelden de regels voor laminair stroming?
if (dp100 <= 3e-6 && dp100 > optdp100) %ligt de dp100 dichter bij 3 micrometer dan het vorige deeltje?
if (dPfilter <= optdPfilter) % is de drukval kleiner, daarom optdPfilter in begin op 500 gesteld zodat er direct aan de juiste voorwaarde word voldaan
optdPfilter=dPfilter;
optdiameterc=diameterc;
optOmega=Omega;
optReomega=Reomega;
optReax=Reax;
optdp100=dp100;
opta=a;
optalpha=alpha;
end
end
%end %hoort bij de formule van de matrix
%end %hoort bij de for loop waarbij we de omega lieten varieren
progressbar([],[],[],stap/n)
end
progressbar([],[],Riswirl/Ro)
end
progressbar([],a/amax)
end
pause(1e-99) % Do something important
progressbar((diameterc-diametercmin)/(diametercmax-diametercmin)) % Update figure
end

progressbar(1)
clc
%Gevraagde antwoorden
optdPfilter
omegahoogste
optdiameterc
optdp100
%dPswirler
%dPtotaal
%dp100
optOmega
optReomega
optReax
opta
optalpha
%Reax
%Reomega
%dPtotaal
[/code]

I also implemented a progessbar created by the great person:Steve Hoelzer
for the progessbar to work the file should be saved in the same folder
Code:
[code]function progressbar(varargin)
% Description:
% progressbar() provides an indication of the progress of some task using
% graphics and text. Calling progressbar repeatedly will update the figure and
% automatically estimate the amount of time remaining.
% This implementation of progressbar is intended to be extremely simple to use
% while providing a high quality user experience.
%
% Features:
% - Can add progressbar to existing m-files with a single line of code.
% - Supports multiple bars in one figure to show progress of nested loops.
% - Optional labels on bars.
% - Figure closes automatically when task is complete.
% - Only one figure can exist so old figures don't clutter the desktop.
% - Remaining time estimate is accurate even if the figure gets closed.
% - Minimal execution time. Won't slow down code.
% - Randomized color. When a programmer gets bored...
%
% Example Function Calls For Single Bar Usage:
% progressbar % Initialize/reset
% progressbar(0) % Initialize/reset
% progressbar('Label') % Initialize/reset and label the bar
% progressbar(0.5) % Update
% progressbar(1) % Close
%
% Example Function Calls For Multi Bar Usage:
% progressbar(0, 0) % Initialize/reset two bars
% progressbar('A', '') % Initialize/reset two bars with one label
% progressbar('', 'B') % Initialize/reset two bars with one label
% progressbar('A', 'B') % Initialize/reset two bars with two labels
% progressbar(0.3) % Update 1st bar
% progressbar(0.3, []) % Update 1st bar
% progressbar([], 0.3) % Update 2nd bar
% progressbar(0.7, 0.9) % Update both bars
% progressbar(1) % Close
% progressbar(1, []) % Close
% progressbar(1, 0.4) % Close
%
% Notes:
% For best results, call progressbar with all zero (or all string) inputs
% before any processing. This sets the proper starting time reference to
% calculate time remaining.
% Bar color is choosen randomly when the figure is created or reset. Clicking
% the bar will cause a random color change.
%
% Demos:
% % Single bar
% m = 500;
% progressbar % Init single bar
% for i = 1:m
% pause(0.01) % Do something important
% progressbar(i/m) % Update progress bar
% end
%
% % Simple multi bar (update one bar at a time)
% m = 4;
% n = 3;
% p = 100;
% progressbar(0,0,0) % Init 3 bars
% for i = 1:m
% progressbar([],0) % Reset 2nd bar
% for j = 1:n
% progressbar([],[],0) % Reset 3rd bar
% for k = 1:p
% pause(0.01) % Do something important
% progressbar([],[],k/p) % Update 3rd bar
% end
% progressbar([],j/n) % Update 2nd bar
% end
% progressbar(i/m) % Update 1st bar
% end
%
% % Fancy multi bar (use labels and update all bars at once)
% m = 4;
% n = 3;
% p = 100;
% progressbar('Monte Carlo Trials','Simulation','Component') % Init 3 bars
% for i = 1:m
% for j = 1:n
% for k = 1:p
% pause(0.01) % Do something important
% % Update all bars
% frac3 = k/p;
% frac2 = ((j-1) + frac3) / n;
% frac1 = ((i-1) + frac2) / m;
% progressbar(frac1, frac2, frac3)
% end
% end
% end
%
% Author:
% Steve Hoelzer
%
% Revisions:
% 2002-Feb-27 Created function
% 2002-Mar-19 Updated title text order
% 2002-Apr-11 Use floor instead of round for percentdone
% 2002-Jun-06 Updated for speed using patch (Thanks to waitbar.m)
% 2002-Jun-19 Choose random patch color when a new figure is created
% 2002-Jun-24 Click on bar or axes to choose new random color
% 2002-Jun-27 Calc time left, reset progress bar when fractiondone == 0
% 2002-Jun-28 Remove extraText var, add position var
% 2002-Jul-18 fractiondone input is optional
% 2002-Jul-19 Allow position to specify screen coordinates
% 2002-Jul-22 Clear vars used in color change callback routine
% 2002-Jul-29 Position input is always specified in pixels
% 2002-Sep-09 Change order of title bar text
% 2003-Jun-13 Change 'min' to 'm' because of built in function 'min'
% 2003-Sep-08 Use callback for changing color instead of string
% 2003-Sep-10 Use persistent vars for speed, modify titlebarstr
% 2003-Sep-25 Correct titlebarstr for 0% case
% 2003-Nov-25 Clear all persistent vars when percentdone = 100
% 2004-Jan-22 Cleaner reset process, don't create figure if percentdone = 100
% 2004-Jan-27 Handle incorrect position input
% 2004-Feb-16 Minimum time interval between updates
% 2004-Apr-01 Cleaner process of enforcing minimum time interval
% 2004-Oct-08 Seperate function for timeleftstr, expand to include days
% 2004-Oct-20 Efficient if-else structure for sec2timestr
% 2006-Sep-11 Width is a multiple of height (don't stretch on widescreens)
% 2010-Sep-21 Major overhaul to support multiple bars and add labels
%

persistent progfig progdata lastupdate

% Get inputs
if nargin > 0
input = varargin;
ninput = nargin;
else
% If no inputs, init with a single bar
input = {0};
ninput = 1;
end

% If task completed, close figure and clear vars, then exit
if input{1} == 1
if ishandle(progfig)
delete(progfig) % Close progress bar
end
clear progfig progdata lastupdate % Clear persistent vars
drawnow
return
end

% Init reset flag
resetflag = false;

% Set reset flag if first input is a string
if ischar(input{1})
resetflag = true;
end

% Set reset flag if all inputs are zero
if input{1} == 0
% If the quick check above passes, need to check all inputs
if all([input{:}] == 0) && (length([input{:}]) == ninput)
resetflag = true;
end
end

% Set reset flag if more inputs than bars
if ninput > length(progdata)
resetflag = true;
end

% If reset needed, close figure and forget old data
if resetflag
if ishandle(progfig)
delete(progfig) % Close progress bar
end
progfig = [];
progdata = []; % Forget obsolete data
end

% Create new progress bar if needed
if ishandle(progfig)
else % This strange if-else works when progfig is empty (~ishandle() does not)

% Define figure size and axes padding for the single bar case
height = 0.03;
width = height * 8;
hpad = 0.02;
vpad = 0.25;

% Figure out how many bars to draw
nbars = max(ninput, length(progdata));

% Adjust figure size and axes padding for number of bars
heightfactor = (1 - vpad) * nbars + vpad;
height = height * heightfactor;
vpad = vpad / heightfactor;

% Initialize progress bar figure
left = (1 - width) / 2;
bottom = (1 - height) / 2;
progfig = figure(...
'Units', 'normalized',...
'Position', [left bottom width height],...
'NumberTitle', 'off',...
'Resize', 'off',...
'MenuBar', 'none' );

% Initialize axes, patch, and text for each bar
left = hpad;
width = 1 - 2*hpad;
vpadtotal = vpad * (nbars + 1);
height = (1 - vpadtotal) / nbars;
for ndx = 1:nbars
% Create axes, patch, and text
bottom = vpad + (vpad + height) * (nbars - ndx);
progdata(ndx).progaxes = axes( ...
'Position', [left bottom width height], ...
'XLim', [0 1], ...
'YLim', [0 1], ...
'Box', 'on', ...
'ytick', [], ...
'xtick', [] );
progdata(ndx).progpatch = patch( ...
'XData', [0 0 0 0], ...
'YData', [0 0 1 1] );
progdata(ndx).progtext = text(0.99, 0.5, '', ...
'HorizontalAlignment', 'Right', ...
'FontUnits', 'Normalized', ...
'FontSize', 0.7 );
progdata(ndx).proglabel = text(0.01, 0.5, '', ...
'HorizontalAlignment', 'Left', ...
'FontUnits', 'Normalized', ...
'FontSize', 0.7 );
if ischar(input{ndx})
set(progdata(ndx).proglabel, 'String', input{ndx})
input{ndx} = 0;
end

% Set callbacks to change color on mouse click
set(progdata(ndx).progaxes, 'ButtonDownFcn', {@changecolor, progdata(ndx).progpatch})
set(progdata(ndx).progpatch, 'ButtonDownFcn', {@changecolor, progdata(ndx).progpatch})
set(progdata(ndx).progtext, 'ButtonDownFcn', {@changecolor, progdata(ndx).progpatch})
set(progdata(ndx).proglabel, 'ButtonDownFcn', {@changecolor, progdata(ndx).progpatch})

% Pick a random color for this patch
changecolor([], [], progdata(ndx).progpatch)

% Set starting time reference
if ~isfield(progdata(ndx), 'starttime') || isempty(progdata(ndx).starttime)
progdata(ndx).starttime = clock;
end
end

% Set time of last update to ensure a redraw
lastupdate = clock - 1;

end

% Process inputs and update state of progdata
for ndx = 1:ninput
if ~isempty(input{ndx})
progdata(ndx).fractiondone = input{ndx};
progdata(ndx).clock = clock;
end
end

% Enforce a minimum time interval between graphics updates
myclock = clock;
if abs(myclock(6) - lastupdate(6)) < 0.01 % Could use etime() but this is faster
return
end

% Update progress patch
for ndx = 1:length(progdata)
set(progdata(ndx).progpatch, 'XData', ...
[0, progdata(ndx).fractiondone, progdata(ndx).fractiondone, 0])
end

% Update progress text if there is more than one bar
if length(progdata) > 1
for ndx = 1:length(progdata)
set(progdata(ndx).progtext, 'String', ...
sprintf('%1d%%', floor(100*progdata(ndx).fractiondone)))
end
end

% Update progress figure title bar
if progdata(1).fractiondone > 0
runtime = etime(progdata(1).clock, progdata(1).starttime);
timeleft = runtime / progdata(1).fractiondone - runtime;
timeleftstr = sec2timestr(timeleft);
titlebarstr = sprintf('%2d%% %s remaining', ...
floor(100*progdata(1).fractiondone), timeleftstr);
else
titlebarstr = ' 0%';
end
set(progfig, 'Name', titlebarstr)

% Force redraw to show changes
drawnow

% Record time of this update
lastupdate = clock;


% ------------------------------------------------------------------------------
function changecolor(h, e, progpatch) %#ok
% Change the color of the progress bar patch

% Prevent color from being too dark or too light
colormin = 1.5;
colormax = 2.8;

thiscolor = rand(1, 3);
while (sum(thiscolor) < colormin) || (sum(thiscolor) > colormax)
thiscolor = rand(1, 3);
end

set(progpatch, 'FaceColor', thiscolor)


% ------------------------------------------------------------------------------
function timestr = sec2timestr(sec)
% Convert a time measurement from seconds into a human readable string.

% Convert seconds to other units
w = floor(sec/604800); % Weeks
sec = sec - w*604800;
d = floor(sec/86400); % Days
sec = sec - d*86400;
h = floor(sec/3600); % Hours
sec = sec - h*3600;
m = floor(sec/60); % Minutes
sec = sec - m*60;
s = floor(sec); % Seconds

% Create time string
if w > 0
if w > 9
timestr = sprintf('%d week', w);
else
timestr = sprintf('%d week, %d day', w, d);
end
elseif d > 0
if d > 9
timestr = sprintf('%d day', d);
else
timestr = sprintf('%d day, %d hr', d, h);
end
elseif h > 0
if h > 9
timestr = sprintf('%d hr', h);
else
timestr = sprintf('%d hr, %d min', h, m);
end
elseif m > 0
if m > 9
timestr = sprintf('%d min', m);
else
timestr = sprintf('%d min, %d sec', m, s);
end
else
timestr = sprintf('%d sec', s);
end
[/code]

Also thanks in advance already everybody for reading this thread
Sign In or Register to comment.