f



matlab fit data problem #4

  Hi all
  I use the code censusgui which is given by coler in his book as
following ,this code try to fit the data
p= [ 75.995  91.972 105.711 123.203 131.669 150.697 ...
     179.323 203.212 226.505 249.633 281.422]';

t = (1900:10:2000)';   % Census years
p as a function of t,but when I change the p to
p= = [ 75.995  91.972 105.711 123.203 131.669 50.697(outlier) ...
     179.323 203.212 226.505 249.633 281.422]';
this code always give me the same graph ,this is totally wrong,can
anyone tell me what is wrong here?
  Thanks a lot
function censusgui(callbackarg)
%CENSUSGUI Try to predict the US population in the year 2010.
% This example is older than MATLAB.  It started as an exercise in
% "Computer Methods for Mathematical Computations", by Forsythe,
% Malcolm and Moler, published by Prentice-Hall in 1977.
% The data set has been updated every ten years since then.
% Today, MATLAB makes it easier to vary the parameters and see the
% results, but the underlying mathematical principles are unchanged:
%
%    Using polynomials of even modest degree to predict
%    the future by extrapolating data is a risky business.
%
% The data is from the decennial census of the United States for the
% years 1900 to 2000.  The task is to extrapolate beyond 2000.
% In addition to polynomials of various degrees, you can choose
% interpolation by a cubic spline, interpolation by a shape-preserving
% Hermite cubic, and a least squares fit by an exponential.
% Error estimates attempt to account for errors in the data,
% but not in the extrapolation model.

% Census data for 1900 to 2000.
% The population on April 1, 2000 was 281,421,906, according to:
% http://www.census.gov/main/www/cen2000.html

p = [ 75.995  91.972 105.711 123.203 131.669 150.697 ...
     179.323 203.212 226.505 249.633 281.422]';

t = (1900:10:2000)';   % Census years
x = (1890:1:2019)';    % Evaluation years
w = 2010;              % Extrapolation target
guess = 320;           % Eyeball extrapolation
z = guess;             % Extrapolated value
dmax = length(t)-1;    % Maximum polynomial degree

if nargin == 0

   % Initialize plot and uicontrols

   shg
   clf reset
   set(gcf,'doublebuffer','on','name','Census gui', ...
       'menu','none','numbertitle','off')
   h.plot = plot(t,p,'bo', x,0*x,'k-', w,0,'.',
[x;NaN;x],[x;NaN;x],'m:');
   darkgreen = [0 2/3 0];
   darkmagenta = [2/3 0 2/3];
   marksize = get(0,'defaultlinemarkersize');
   set(h.plot(3),'color',darkgreen,'markersize',4*marksize-6)
   set(h.plot(4),'color',darkmagenta)
   axis([min(x) max(x) 0 400])
   title('Predict U.S. Population in 2010')
   ylabel('Millions')

   h.text =
text(w-16,z+10,'predict','color',darkgreen,'fontweight','bold');
   h.model = uicontrol('units','norm','pos',[.20 .80 .20 .05], ...
           'style','popup','background','white','string', ...
           {'census data','polynomial','pchip','spline','exponential'},
....
           'callback','censusgui([])');
   h.deg = uicontrol('units','norm','pos',[.26 .75 .13 .04], ...
           'tag','degree','style','text','background','white', ...
           'userdata',3,'string','degree = 3');
   h.ls = uicontrol('units','norm','pos',[.20 .75 .05 .04], ...
           'style','push','string','<','fontweight','bold', ...
           'callback','censusgui(''<'')');
   h.gt = uicontrol('units','norm','pos',[.40 .75 .05 .04], ...
           'style','push','string','>','fontweight','bold', ...
           'callback','censusgui(''>'')');
   h.err = uicontrol('units','norm','pos',[.20 .65 .20 .05], ...
           'style','check','background','white', ...
           'string','error estimates','callback','censusgui([])');
   set(gcf,'userdata',h);
   uicontrol('style','push','units','normal','pos',[.85 .02 .10 .06],
....
      'string','close','callback','close(gcf)')
   callbackarg = [];

else

   h = get(gcf,'userdata');

end

% Polynomial degree

d = get(h.deg,'userdata');
if isequal(callbackarg,'<'), d = d - 1; end
if isequal(callbackarg,'>'), d = d + 1; end
set(h.deg,'userdata',d)

% Update plot with new model

models = get(h.model,'string');
model = models{get(h.model,'value')};
switch model
   case 'census data'
      y = NaN*x;
      z = 320;
   case 'polynomial'
      s = (t-1950)/50;   c = polyfit(s,p,d);
      s = (x-1950)/50;   y = polyval(c,s);
      s = (w-1950)/50;   z = polyval(c,s);
   case 'pchip'
      y = pchip(t,p,x);
      z = pchip(t,p,w);
   case 'spline'
      y = spline(t,p,x);
      z = spline(t,p,w);
   case 'exponential'
      c = polyfit(log(t),log(p),1);
      y = exp(polyval(c,log(x)));
      z = exp(polyval(c,log(w)));
end
set(h.plot(2),'ydata',y);
set(h.plot(3),'ydata',z);
set(h.text,'pos',[w-18,min(max(z+10,20),380)],'string',sprintf('%8.3f',z))

% Update controls

switch model
   case 'census data'
      set(h.err,'vis','off','value',0);
      set([h.deg; h.gt; h.ls],'vis','off');
      set(h.text,'pos',[w-16,z+10],'string','predict')
   case 'polynomial'
      set(h.err,'vis','on','pos',[.20 .68 .20 .05]);
      set(h.deg,'vis','on','string',['degree = ' num2str(d)]);
      set([h.gt; h.ls],'vis','on','enable','on');
      if d == 0, set(h.ls,'enable','off'), end
      if d == dmax, set(h.gt,'enable','off'), end
   otherwise
      set(h.err,'vis','on','pos',[.20 .75 .20 .05]);
      set([h.deg; h.gt; h.ls],'vis','off');
end

% Display error estimates if requested

if get(h.err,'value') == 1
   errest = errorestimates(model,t,p,x,y,d);
   set(h.plot(4),'vis','on','ydata',errest);
else
   set(h.plot(4),'vis','off');
end


% ------------------------------------------------

function errest = errorestimates(model,t,p,x,y,d)
% Provide error estimates for censusgui

switch model
   case 'polynomial'
      if d > 0
         V(:,d+1) = ones(size(t));
         s = (t-1950)/50;
         for j = d:-1:1
            V(:,j) = s.*V(:,j+1);
         end
         [Q,R] = qr(V);
         R = R(1:d+1,:);
         RI = inv(R);
         E = zeros(length(x),d+1);
         s = (x-1950)/50;
         for j = 1:d+1
            E(:,j) = polyval(RI(:,j),s);
         end
         sig = 10;   % Rough estimate
         e = sig*sqrt(1+diag(E*E'));
         errest = [y-e; NaN; y+e];
      else
         errest = [y-NaN; NaN; y+NaN];
      end
   case {'pchip','spline'}
      n = length(t);
      I = eye(n,n);
      E = zeros(length(x),n);
      for j = 1:n
         if isequal(model,'pchip')
            E(:,j) = pchip(t,I(:,j),x);
         else
            E(:,j) = spline(t,I(:,j),x);
         end
      end
      sig = 10;  % Rough estimate
      e = sig*sqrt(1+diag(E*E'));
      errest = [y-e; NaN; y+e];
   case 'exponential'
      V = [ones(size(t)) log(t)];
      [Q,R] = qr(V);
      c = R\(Q'*log(p));
      r = log(p) - V*c;
      E = [ones(size(x)) log(x)]/R(1:2,1:2);
      sig = norm(r);
      e = sig*sqrt(1+diag(E*E'));
      errest = [y.*exp(-e); NaN; y.*exp(e)];
end


Delete Reply Forward Spam Move...
Previous | Next | Back to Messages

-1
11/26/2005 1:03:15 AM
comp.soft-sys.matlab 211265 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

0 Replies
827 Views

Similar Articles

[PageSpeed] 7

Reply:

Similar Artilces:

matlab fit data problem
Hi all I use the code censusgui which is given by coler in his book as following ,this code try to fit the data p= [ 75.995 91.972 105.711 123.203 131.669 150.697 ... 179.323 203.212 226.505 249.633 281.422]'; t = (1900:10:2000)'; % Census years p as a function of t,but when I change the p to p= = [ 75.995 91.972 105.711 123.203 131.669 50.697(outlier) ... 179.323 203.212 226.505 249.633 281.422]'; this code always give me the same graph ,this is totally wrong,can anyone tell me what is wrong here? Thanks a lot function censusgui(callbackarg) %CENSUSGUI Try to ...

matlab fit data problem #2
Hi all I use the code censusgui which is given by coler in his book as following ,this code try to fit the data p= [ 75.995 91.972 105.711 123.203 131.669 150.697 ... 179.323 203.212 226.505 249.633 281.422]'; t = (1900:10:2000)'; % Census years p as a function of t,but when I change the p to p= = [ 75.995 91.972 105.711 123.203 131.669 50.697(outlier) ... 179.323 203.212 226.505 249.633 281.422]'; this code always give me the same graph ,this is totally wrong,can anyone tell me what is wrong here? Thanks a lot function censusgui(callbackarg) %CENSUSGUI Try to ...

[Mac 10.4.10, MATLAB 7.4] MATLAB can't find my X11
How do I tell MATLAB where to find my X11? I have both dynamic and static X11 libraries in my /Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib path, but can't start MATLAB because, so it says, it can't find my X11. I tried downloading and (re)installing X11, but couldn't 'cause, I was told, I already have a newer version on my computer! I tried (re)installing MATLAB, but get the message "Can't find X11. You may go ahead and install MATLAB, but you won't be able to run it 'til you install X11" Well, the X11 installer won't let me install it 'cause...

Matlab v7 data file in Matlab v6.5
Hi there I want to save my data into data file in Matlab v7 (R14). How can I save it in a manner such that it is also loadable in Matlab v6.5 (R13) ? As at the moment, Matlab v6.5 interprets a Matlab v7 saved data file as a corrupt file. Thanks in advance, rehan Rehan Ahmad wrote: > > > Hi there > > I want to save my data into data file in Matlab v7 (R14). How can I > save it in a manner such that it is also loadable in Matlab v6.5 > (R13) ? As at the moment, Matlab v6.5 interprets a Matlab v7 saved > data file as a corrupt file. > > Thanks in advance, > reh...

Matlab installation problem #4
I'm getting error while installing Matlab7.0.4 on Windows7. ----- The following error was detected while installing MATLAB: C:\Program Files (x86)\MATLAB704\bin\win32\libguide40.dll (The process cannot access the file because it is being used by another process) Would you like to retry installing MATLAB? If you press No, the installer will exit without completing the installation. More information can be found at C:\Users\ISHMIN~1\AppData\Local\Temp\mathworks_installer.log ------ I have checked libguide40.dll file is not in use by other program. I have already changed the windows theme...

How to fit multidimensional data in MATLAB?
Hi All, Does any one know how to fit data of the following type: x - column of real numbers (first independent variable) y - column of real numbers (second independent variable) f - dependent variable, also a column of real numbers Need to fit the f(x,y) by: A*x+B*y+C and ge the A,B,C coefficients. I do not have the optimization toolbox installed, so cannot take advantage of the 'lsqcurvefit' or else. Thanks! Vahan "Vahan S" <femtovahan@yahoo.com> wrote in message <g60h39$fd3$1@fred.mathworks.com>... > Hi All, > > Does any one know how to fit da...

MATLAB Compiler 4.6 Problems
When I try to compile a file from MATLAB into a stand alone C++ library using the command: mcc -W cpplib:libmatrix -T compile:lib -v addmatrix.m multiplymatrix.m eigenvalfn.m I get the error message: Error libmatrix.cpp: 146 syntax error; found `void' expecting `;' Error libmatrix.cpp: 146 missing parameter type Error libmatrix.cpp: 146 syntax error; found `&' expecting `)' Error libmatrix.cpp: 146 skipping `&' `a' `,' Error libmatrix.cpp: 147 syntax error; found `const' expecting `{' Error libmatrix.cpp: 147 redeclaration of `mwArray' previou...

MatLab Compiler 4.3 problem
Hi, I just upgraded from MatLab R14SP2 to R14SP3 and recompiled all my dll's with the COMTOOL. However, now the DLL of my model that takes about 2 hours to run on a Pentium 4 3GHz machine does not exit when it has finished running. This problem does not happen with the Compiler 4.2. I'm not sure how to fix this, so in the mean time I will revert back to R14SP2. Thanks, Nick, Nick - Did you find a solution for this? ...

Problem with Video data analysis in Matlab
Hello everyone, I am working on a project where I need to analyse video data in real time to control the robot. I need to get a frame from video data received from CCD camera and perform some image processing and generate a control action based on it and then again repeat the same process for next frame. I have created a video object using videoinput function and am getting a frame from this video data using getsnapshot function but I am facing some memory problems(like java.lang.memory out and Matlab crashes)while running the program in a loop. I dont know much about the settings and memory ...

exporting data from a matlab figure #4
hi eveyrone i have a figure saved, it's a normal plot(x,y) plot where x and y are some vectors. unfortunately i lost the x and y vectors and i need them. all i have is the figure in normal ..fig format. i can click the entries on the line and see my data there -- is a way i can rescue the vectors without going from point to point (there's a few hundred :[)??? please help! thanks. k ...

a problem about data from Matlab to VBA #2
Hi all: i am a new learner.i have a problem about getting data from Matlab to VB.And when i compile it ,i find that a message 'array is not defined'.But i do have defined it.Can you tell me about this problem ?thank you very much !This is my code. Sub Main Const N =10 'number of particle Const Nvar = 30 'number of variable Dim Matlab As Object Dim result As String Dim ZReal(N-1,Nvar-1) As Double Dim ZR() As Double Dim i, j As Integer Set Matlab = CreateObject("Matlab.Application") result = Matlab.Execute("X = randn(N,Nvar);") Call Matlab.GetFullMatri...

problems with code to convert ncs file in matlab under Matlab R14(2004)
Hello to everyone, Ill try to run Nlx2MatCSC ( a code from neuralynx than convert continuous file to matlab variables) in Matlab R14 (2004), and it doesn't work: When I type: >> [Timestamp, ChanNum, SampleFrequency, NumValSamples, Samples] = Nlx2MatCSC(Filename, [1 1 1 1 1], 0, 3, [0 4 9]); ??? Attempt to execute SCRIPT Nlx2MatCSC as a function. I heard that this code is running in Matlab 2007a and newer, but...what about this old version? Any help, Cheers ...

some problems of codes of MATLAB 7.0 working on MATLAB 6.5
I have used MATLAB for few hours.So I don't know the differences between version 6.5 and 7.0.I want to use some codes of MATLAB 7.0, but they doesn't work in MATLAB 6.5.How to change these codes so that they can work in matlab 6.5.Waiting for your help. Thank you . The codes are like this .I think changing the function findPI may work ,but I don'y know how % PIfun.m % Evaluate a function used to find the PI-line, using Kyle Champley's % method. % % Adam Wunderlich % last update: 5/18/06 function y = PIfun(r,R,h,gamma,x3,sb) temp = R - r*cos(gamma-sb); y = h*((pi - 2*atan(r*sin(gamma-sb)/temp))*(1 + (r^2 - R^2)/ (2*R*temp)) ... + sb) - x3; % find_PI_Line.m % % Find the the parametric interval corresponding to the unique PI-line % passing through the point x for a given helical pitch. % This code implements the method of Kyle Champley. % inputs: P = pitch (cm/turn), R = helix radius, delta_s = s stepsize, x % output: PI = [sb st] % % Adam Wunderlich % last update: 5/18/06 function [PI] = findPI(P,R,delta_s,x) h = P/(2*pi); r = sqrt(x(1)^2+x(2)^2); gamma = atan2(x(2),x(1)); options = optimset('TolX',h*delta_s/100,'FunValCheck','on'); [sb,fval,exitflag] = fzero(@(sb) PIfun(r,R,h,gamma,x(3),sb),... [(x(3)-h*pi)/h,x(3)/h],options); if exitflag ~=1, disp('Error: PI invalid'); end % note that beta=sb in Kyle's formula alphaX = atan(r*sin(gamma-sb)/(R - r*cos(gamma-sb))); st = sb + pi -...

convert a .mat file (Matlab 6.5) to a .mat file(Matlab 4)
Hello I've just started using a program, and i need to import data to this program. There are other options but I prefer to import it from matlab...but this program only support matlab 4 version. I want to convert it my file but i son't know why....I've proved with save as..but i had no chance. What i have to do?Someone can help me? Thank you very much! Bye!! Michael wrote: > Hello I've just started using a program, and i need to import data to > this program. There are other options but I prefer to import it from > matlab...but this program only support matlab 4 v...

Problem with receiving data from matlab serial port
hi, I AM Raghu Nandan Ravi and I am currently doing a project on transmission of digital video images using Matlab. I am having a problem with reading the data from the device connected to my serial port. when ever the receive buffer is full and when i simulate the program i have written it is giving error message that the time out has reached before the terminator occured. can any one help me with this problem. the program i have written is shown below.: ************************************************************ obj=serial('com6') set(obj,'baudrate',19200,'inp...

Problem related to distribution fitting tool in matlab
i am trying to fit the lognormal distribution for the dataset i have. i have 1500 value of leakage power nanorange. when i am fitting the distribution using dftitool, the range of values for pdf are coming in the range of e^10 range. i want probability values in the range of 0 to 1. How can i do this?????/ On 3/15/2012 3:37 AM, lokesh wrote: > i am trying to fit the lognormal distribution for the dataset i have. i > have 1500 value of leakage power nanorange. when i am fitting the > distribution using dftitool, the range of values for pdf are coming in > the range of e^10 range. ...

MATLAB CPP arrays (MATLAB 7.4, Visual Studio 2005 .NET CPP)
Hi everyone, I have faced the following problem using MATLAB: I have a .NET assembly made COM visible, the assembly contains a class; in the class there is a function with the following signature: void CreateNew_fii(double x[], int y, int z); As you can see, I'd like to pass a double array and two integers to the function. However, MATLAB recognizes the function as: CreateNew_fii = double CreateNew_fii(handle, double, int32, int32) And throws an error every time I invoke it. According to MATLAB support, the function should be recognized as: CreateNew_fii = void CreateNew_fii(handle, ...

Problem when runing a .m file in Matlab 7 #4
Hello, i developed a project in Matlab 6.5. When i runed it in Matlab 7 i get a Warning and nothing is working. The warning i get is this: Warning: Function call mgrade invokes inexact match C:\MATLAB7\toolbox\fmid\MGRADE.M. > In fuzzyMF at 15 In wYValue at 27 In optimalMPC at 86 In optimal at 203 Warning: Function call optimalBBM invokes inexact match C:\matlab7\work\optimalBBM.M. Can somebody help me out? I have no idea what is going on and all this was working on Matlab 6.5. Thank You, Miguel May be you do not have all the toolboxes installed for matlab 7, which you had in ...

FC 7, matlab 7.4 gui problems
is anyone having problems with using a buttonmotion function for guis in fedora core 7 matlab 7.4? even when the function is empty (no computation) it makes the motion of the mouse slow/jerky. thanks looks like the problem is actually caused by setting the pointer to fullcross. this problem was not ahppening for matlab 7sp2? does anyone know about a difference between the two version that would cause problems drawing the full cross? ...

To find solution for river dispersion problem, with matlab #4
Can anybody tell me, how to model this equation, which is 1 D problem Governing equation = "dC/dt=D*dC^2/dx^2U*dC/dx" where U = velocity, C= concentration x = space variable need quick reply ...

which matlab function for fitting 3d data (I think nonlinear)
I have a dataset of x,y and z values. How can a find the parameters p of the following equation: D = SQRT( A^2 + B^2 + C^2 ) with A = x*p(1) + p(2) B = y*p(3) + p(4) + A*p(5) C = z*p(6) + p(7) + A*p(8) + B*p(9) D is a constant value and it is known. Which Matlab function is the right one for this fitting problem? Thanks, Markus ...

Matlab Codes For Importing data & Fitting Curves
I am struggling to write codes to import data from the Web and do non-linear fitting. ...

Matlab plots outside Matlab
I'm making an end-user application where I would like to use Matlab functionality both for calculation and plotting. Matlabs GUI builder guide does not satisfy my needs (no support for f.ex. internal frames and other nescessities), so I'm planning to compile my Matlab code and use other API (Java, QT or something) for GUI. My problem is then, that I loose access to the neat plotting commands availible under matlab GUI... Is there a way of integrating Matlabs plot functionality into another GUI system? - has it been done? - I appreciate any response! - P�l Berge ...

Does MATLAB Fit......!!!
I've some points (x, y, z), I like to get a fitted line (least square). Is it possible to get the fitted line by using any Matlab routine? If yes, please let me know as early as possible. Chris wrote: > > > I've some points (x, y, z), I like to get a fitted line (least > square). > Is it possible to get the fitted line by using any Matlab routine? > If > > yes, please let me know as early as possible. Yes! P = [X(:) Y(:) ones(length(X(:)),1)] \ X(:) ; gives you the parameters P that fits the line z = P(1)*X + P(2)*Y + P(3) in the LSQ sense. hth, Jos Email...

Web resources about - matlab fit data problem #4 - comp.soft-sys.matlab

Problem novel - Wikipedia, the free encyclopedia
Working class, or proletarian novels are often also social problem novels . This was in many ways a reaction to rapid industrialization , and ...

China has a $777 billion problem with unpaid bills
Not since 1999 have China's companies had so much trouble getting customers to actually pay for what they've bought.

Why Telstra's network problems could cause long-term damage
Australian phone and internet providers suffer daily network problems and outages. But Telstra falls the hardest when customers see behind the ...

Why Telstra's network problems could cause long-term damage
Australian phone and internet providers suffer daily network problems and outages. But Telstra falls the hardest when customers see behind the ...

China has a $777 billion problem with unpaid bills
Not since 1999 have China's companies had so much trouble getting customers to actually pay for what they've bought.

China has a $777 billion problem with unpaid bills
Not since 1999 have China's companies had so much trouble getting customers to actually pay for what they've bought.

John Oliver: All Of The Legal, Economic, And Practical Problems With Donald Trump’s Wall
About the Trump wall. There are just a few problems with that...

Mini-review: tvOS 9.2 fixes all the Apple TV’s biggest problems
... the work of building the Apple TV into a platform rather than just a streaming box. That platform mostly seems solid, and its biggest problems ...

Leak suggests iPhone 7 might actually address the iPhone’s biggest problem
... and a brand new report brings us more information suggesting that Apple's new iPhone 7 might actually address the iPhone lineup's biggest problem. ...

The world’s wealthiest failed state... a population that’s complicit.... a very strong implantation ...
... its success in arresting [the alleged leader of the Paris massacre Salah] Abdeslam, Belgium continues to present a special security problem ...

Resources last updated: 3/22/2016 7:58:19 PM