Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PIERWSZEEE
- clear all;
- close all;
- V=0.33;
- C1 = 1;
- C2 = 2*C1;
- i=0;
- max = 2;
- for r=0:0.1:max
- i=i+1;
- r
- P(i) = (C1*2*pi*r*r*r + 2*V*C2)/r;
- end
- hold on;
- plot(0:0.1:max, P, 'r');
- C2 = C1;
- i=0;
- for r=0:0.1:max
- i=i+1;
- P2(i) = (C1*2*pi*r*r*r + 2*V*C2)/r;
- end
- plot(0:0.1:max, P2, 'g');
- a=0;
- b=1;
- k = (sqrt(5)-1)/2;
- xL = b-k*(b-a);
- xR = a+k*(b-a);
- while (b-a)>1e-6
- if f(xL)<f(xR)
- b = xR;
- xR = xL;
- xL = b-k*(b-a);
- else
- a = xL;
- xL = xR;
- xR = a+k*(b-a);
- end
- end
- xopt = (a+b)/2;
- wymiary=[xopt,0.33*(1/(pi*xopt^2))]
- a=0;
- b=1;
- k = (sqrt(5)-1)/2;
- xL = b-k*(b-a);
- xR = a+k*(b-a);
- while (b-a)>1e-6
- if f1(xL)<f1(xR)
- b = xR;
- xR = xL;
- xL = b-k*(b-a);
- else
- a = xL;
- xL = xR;
- xR = a+k*(b-a);
- end
- end
- xopt = (a+b)/2;
- wymiary=[xopt,0.33*(1/(pi*xopt^2))]
- .....................
- f1
- function [ f ] = f( x )
- f=0.66*(1/x)+4*pi*x^2;
- end
- f
- function [ f ] = f( x )
- f=0.66*(1/x)+2*pi*x^2;
- end
- ------------------------------------------------------------------------
- TRZECIE333333333333
- close all;
- clear all;
- x = fun(0,0);
- for i=-100:100
- for j=-100:100
- if fun(i,j)<x(1)
- x(1) = fun(i,j);
- x(2) = i;
- x(3) = j;
- end
- end
- end
- x
- ----------------------------------------------------------------------------
- 222222222222222:
- clear all;
- close all;
- optimset('MaxFunEvals', 1e15);
- load lab10_2.mat;
- in = in_all(:,3);
- initial_f = 1;0.001;
- initial_A = 1;
- initial_a = 1;
- % estymacja parametrów
- fs = 0;
- Nx = length(in);
- initParm = [ initial_f, initial_A, initial_a ]; % parametry początkowe
- outParm = fminsearch( @(x) fitSinDamp(x, in, fs, Nx) , initParm );
- estimated_f = outParm(1);
- estimated_A = outParm(2);
- estimated_a = outParm(3);
- x=0:10/999:10;
- y1 = exp(-estimated_a*x)*estimated_A.*sin(2*pi*estimated_f*x);
- %plot(0:10/999:10, y1);
- %plot(0:10/999:10, in, 'r');
- %hold on
- max(std(y1'-in))
- %plot(in, 'r');
- % porównanie przebiegu wygenerowanego z odtworzonym
- % ToDo
- ----------
- function y = fitSinDamp( parm, x, fs, Nx )
- % x – docolowy sygnał
- % fs – częstotliwość prókowania
- % Nx – długość sygnału
- f = parm(1); % częstotliwość sinusoidy
- A = parm(2); % początkowa amplituda
- a = parm(3); % szybkość opadania
- z=0:10/999:10;
- y = exp(-a*z)*A.*sin(2*pi*f*z);
- y=std(y'-x);
- % ToDo – mniejsza wartość == lepsze dopasowanie
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement