I am trying to feed forward back propagation but after network training, when simulating and printing the output of simulation, I can't see any value near to target, but it is just one number.
The code is below. What is wrong or what is the problem?
Feed forward back propagation:
>> load('E:/Inputdata.txt');
>> load('E:/Targetdata.txt');
>> P = Inputdata(1:406,1:3);
>> T = Targetdata(1:406,1);
>> S = Inputdata(407:507,1:3);
>> Y = Targetdata(407:507,1);
>> [pn,minp,maxp,tn,mint,maxt]=premnmx(P',T');
>> [sn,mins,maxs,yn,miny,maxy]=premnmx(S',Y');
>> net =newff(minmax(pn),[5 2 1],{'tansig','tansig','tansig'},'traingdm');
>> net.trainParam.show = 50;
>> net.trainParam.lr = 0.4;
>> net.trainParam.epochs = 3200;
>> net.trainParam.goal = 1e-5;
>> net=train (net,pn,tn);
>> A = sim (net,sn);
>> Z=postmnmx(A',miny,maxy);
>> [Y Z]
75.8810 80.0903
76.5849 80.0903
77.2888 80.0903
77.9927 80.0903
78.6966 80.0903
79.4005 80.0903
80.1044 80.0903
80.8083 80.0903
128.6739 80.0903
129.3778 80.0903
130.0817 80.0903
130.7856 80.0903
131.4895 80.0903
132.1934 80.0903
132.8973 80.0903
133.6012 80.0903
Y is the real target, and Z the 2nd column in the output from the net.
This output does not satisfy what it must do, because if I give other simulation set so it is the same, the output must be near to real target.
Related
I have a cell array with size (n,1) that includes a function handle. Every cell has to include specific function handle and the summation of function handles in the previous cells. How can I perform this operation? To clarify this is an illustration.
A = cell(size(ones(n,1)));
for i = 1 : n
A{i,1} = #(x) A{i-1,1} + i .* x;
end
How to get A{n,1} at x = 2 (for example)
You are actually pretty close, but you need to add a special case for i = 1 and you need to call the function:
n = 10;
A = cell(size(ones(n,1)));
A{1,1} = #(x) 1 .* x;
for ii = 2 : n
A{ii,1} = #(x) A{ii-1,1}(x) + ii .* x;
end
I replaced i with ii, to avoid confusion with complex numbers. For the case n = 10:
>> A{n}(2)
ans =
110
Recalling #gnovice comment, you can also just make a cell array of the handles, and then call a function that sums them up to n:
N = 10;
A = cell(N,1);
A{1} = #(x) 1.*x;
for k = 2:N
A{k} = #(x) k.*x;
end
% the following function sums the output of A{1}(x) to A{n}(x):
f = #(n,x) sum(cellfun(#(c) c(x),A(1:n)));
The result:
>> f(5,2)
ans =
30
>> f(N,2)
ans =
110
This way, every change of the functions in A will have an immediate effect upon redefining f:
>> A{3} = #(x) -x;
>> f = #(n,x) sum(cellfun(#(c) c(x),A(1:n)));
>> f(N,2)
ans =
102
>> f(5,2)
ans =
22
I'm trying to create a bode plot using hertz instaead of rads/s, but I don't know how to do that.
My code right now is:
R1 = 200
R2 = 1000
C1 = 2.5*10^-5
C2 = 1*10^-6
G = ((1/(s*C1))*R2)/((1/(s^2*C1*C2))+(R2/(s*C1))+(R1/(s*C1))+R1*R2+(1/(s*C2)))
bode(G)
Thanks
Yes, see the doc for bodeplot, and/or setoptions. The example from the doc is:
>> sys = tf(1,[1 1]);
>> h = bodeplot(sys);
>> p = getoptions(h);
>> p.FreqUnits = 'Hz';
>> setoptions(h,p);
I'm using MATLAB R2017a. I've got two script files in the workspace. In the first one I solve a system of nonlinear equations and I set a condition on the variables that they must be positive. In the second files I do the same but without this condition. I run the first file and get the positive solution. When I run the second one afterwards, I get the positive solution as well even though I didn't create any conditions on the vars. If I put "clear all" then in the second file I get not only positive solution. What's going on? I didn't seem to have it in previous versions of MATLAB.
Here's the code of the first file:
function systrajs
c = 0.19;
mu1 = 2.1;
s1 = 0.01;
r2 = 0.94;
b = 0.03;
s2 = 0;
par = [c mu1 s1 r2 b s2];
eqpoints(par);
end
function eqpoints(par)
c = par(1);
mu1 = par(2);
s1 = par(3);
r2 = par(4);
b = par(5);
s2 = par(6);
syms x y z positive
F = [c*y - mu1*x + x*z + s1; r2*y*(1 - b*y) - x*y; z - x*y + s2];
eq = solve(F, [x y z]);
eq = double([eq.x eq.y eq.z]');
disp('The solution:');
disp(eq);
end
Here's the code of the second script file:
function syssolve
syms x y z
c = 0.19;
mu1 = 2.1;
s1 = 0.01;
r2 = 0.94;
b = 0.03;
s2 = 0;
F = [c*y - mu1*x + x*z + s1; r2*y*(1 - b*y) - x*y; z - x*y];
eq = solve(F,[x y z]);
sol = double([eq.x eq.y eq.z]');
disp(sol);
end
So, as you can see, in the first file I marked the variables as positive. And it really gives only positive solutions. In the second one solution may be of any type. But if I run it right after the first file I still will be getting only positive solutions. If I close and open the second file (or just write "clear all") then I'm getting not only positive solutions. Why?
I have a problem using the MATLAB DAE-solvers.
I'm trying to simulate the behaviour of a mechanical system using lagrangien mechanics. To do so, I followed the following tutorial to use MATLAB'sDAE-solvers.
But when I ran my code, I got the following error message:
Warning: Failure at t=5.076437e-01. Unable to meet integration tolerances without reducing the step size below the smallest value allowed
(1.803513e-15) at time t.
In ode15i (line 406)
Trying to find my mistake, I literally copied the code from the tutorial and ran it. The code is as follows:
syms l g m real
syms x(t) y(t) T(t)
eqns = [(m*diff(x(t),2) - T(t)/l*x(t)),
(m*diff(y(t),2) - T(t)/l*y(t) + m*g),
(x(t)^2 + y(t)^2 - l^2) ];
vars = [x(t); y(t); T(t)];
[eqns, vars] = reduceDifferentialOrder(eqns, vars);
if(~isLowIndexDAE(eqns, vars))
[DAEs, DAEvars] = reduceDAEIndex(eqns, vars);
[DAEs, DAEvars] = reduceRedundancies(DAEs, DAEvars);
end
%change to function, set parameters
f = daeFunction(DAEs, DAEvars, m, l, g);
m = 1.0;
r = 1.0;
g = 9.81;
F = #(t, Y, YP) f(t, Y, YP, m, r, g);
%get initial conditions
y0est = [0.5*r; -0.8*r; 0; 0; 0; 0; 0];
yp0est = zeros(7,1);
opt = odeset('RelTol', 10.0^(-7), 'AbsTol' , 10.0^(-7));
[y0, yp0] = decic(F, 0, y0est, [], yp0est, [], opt);
%simulate
[t,y] = ode15i(F, [0, 5], y0, yp0, opt);
I'm trying to calculate this convolution:
x[n] = δ[n+1] + δ[n] - δ[n-1]
h[n] = (1/2)^n * u[n] . u[n] is the step function.
Here's my code:
>> n=[-10:10];
>> x=zeros(1,length(n));
>> x(n==-1)=1;
>> x(n==0)=1;
>> x(n==1)=-1;
>> u=heaviside(n);
>> h=(1/2).^n * u;
??? Error using ==> mtimes
Inner matrix dimensions must agree.
How do you exactly type my h[n]? What if it's u[n-1] instead?
>> n=[-10:10];
>> x=zeros(1,length(n));
>> x(n==-1)=1;
>> x(n==0)=1;
>> x(n==1)=-1;
>> u=heaviside(n);
>> h=(1/2).^n .* u; %Note the element wise operation .*
>> conv(x,h)