Tag Archives: matlab
The ann program doesn’t run all 50 epochs that specified.
Here is the code:
inputs = readmatrix(‘C:UserstanmoDownloadsInput-Station-2.xlsx’);
targets = readmatrix(‘C:UserstanmoDownloadsTarget-Station-2.xlsx’);
inputs = inputs’; % Transpose if necessary
targets = targets’; % Transpose if necessary
net = feedforwardnet([10 10]);
net.trainFcn = ‘trainlm’; % Using Levenberg-Marquardt backpropagation
net.trainParam.epochs = 50;
net.trainParam.lr = 0.01;
net.trainParam.max_fail = 50; % Maximum validation failures
net.divideParam.trainRatio = 0.70;
net.divideParam.valRatio = 0.15;
net.divideParam.testRatio = 0.15;
net.trainParam.goal = 0; % Essentially remove the performance goal// added later
net.trainParam.min_grad = 1e-10; % Set a very small gradient goal
[net, tr]= train(net, inputs, targets);
outputs = net(inputs);
performance = perform(net, targets, outputs);
plotperform(tr)
I can’t fix the number of iteration or epoch. It does a random iteration in different time and plots graph for random epoch values.Here is the code:
inputs = readmatrix(‘C:UserstanmoDownloadsInput-Station-2.xlsx’);
targets = readmatrix(‘C:UserstanmoDownloadsTarget-Station-2.xlsx’);
inputs = inputs’; % Transpose if necessary
targets = targets’; % Transpose if necessary
net = feedforwardnet([10 10]);
net.trainFcn = ‘trainlm’; % Using Levenberg-Marquardt backpropagation
net.trainParam.epochs = 50;
net.trainParam.lr = 0.01;
net.trainParam.max_fail = 50; % Maximum validation failures
net.divideParam.trainRatio = 0.70;
net.divideParam.valRatio = 0.15;
net.divideParam.testRatio = 0.15;
net.trainParam.goal = 0; % Essentially remove the performance goal// added later
net.trainParam.min_grad = 1e-10; % Set a very small gradient goal
[net, tr]= train(net, inputs, targets);
outputs = net(inputs);
performance = perform(net, targets, outputs);
plotperform(tr)
I can’t fix the number of iteration or epoch. It does a random iteration in different time and plots graph for random epoch values. Here is the code:
inputs = readmatrix(‘C:UserstanmoDownloadsInput-Station-2.xlsx’);
targets = readmatrix(‘C:UserstanmoDownloadsTarget-Station-2.xlsx’);
inputs = inputs’; % Transpose if necessary
targets = targets’; % Transpose if necessary
net = feedforwardnet([10 10]);
net.trainFcn = ‘trainlm’; % Using Levenberg-Marquardt backpropagation
net.trainParam.epochs = 50;
net.trainParam.lr = 0.01;
net.trainParam.max_fail = 50; % Maximum validation failures
net.divideParam.trainRatio = 0.70;
net.divideParam.valRatio = 0.15;
net.divideParam.testRatio = 0.15;
net.trainParam.goal = 0; % Essentially remove the performance goal// added later
net.trainParam.min_grad = 1e-10; % Set a very small gradient goal
[net, tr]= train(net, inputs, targets);
outputs = net(inputs);
performance = perform(net, targets, outputs);
plotperform(tr)
I can’t fix the number of iteration or epoch. It does a random iteration in different time and plots graph for random epoch values. epoch, iteration, ann MATLAB Answers — New Questions
Modulation transfer function (MTF)
Hi,
I’m going to evaluate the MTF of an imaging system. I have a MatLab code and it works fine and my question is not related with programming.
I would like to know why spatial resolution is evaluated at the 50% of the MTF. In the web it is written that it is because it correlates well with our perception of sharpness, but other web site (wikipedia) says that is it raleted with the best focus position… Is there any good reference that explains properly this point?
Thank youHi,
I’m going to evaluate the MTF of an imaging system. I have a MatLab code and it works fine and my question is not related with programming.
I would like to know why spatial resolution is evaluated at the 50% of the MTF. In the web it is written that it is because it correlates well with our perception of sharpness, but other web site (wikipedia) says that is it raleted with the best focus position… Is there any good reference that explains properly this point?
Thank you Hi,
I’m going to evaluate the MTF of an imaging system. I have a MatLab code and it works fine and my question is not related with programming.
I would like to know why spatial resolution is evaluated at the 50% of the MTF. In the web it is written that it is because it correlates well with our perception of sharpness, but other web site (wikipedia) says that is it raleted with the best focus position… Is there any good reference that explains properly this point?
Thank you image processing, image analysis, mtf MATLAB Answers — New Questions
Input is a valid integer
How to check if the value entered by the user is a valid integer and not a negative number(such as -1,-9,-10 etc) or characters/strings(such as a, i,thank you)or special symbols(such as @,* etc) and also that is not equal to 0?How to check if the value entered by the user is a valid integer and not a negative number(such as -1,-9,-10 etc) or characters/strings(such as a, i,thank you)or special symbols(such as @,* etc) and also that is not equal to 0? How to check if the value entered by the user is a valid integer and not a negative number(such as -1,-9,-10 etc) or characters/strings(such as a, i,thank you)or special symbols(such as @,* etc) and also that is not equal to 0? checking for valid integer MATLAB Answers — New Questions
Error in ode45 solution
Ode45 results dont maintain power conservation for some cases. How to ensure that power conservation is maintained?
While using ode45 to solve coupled differential equation, when one of the input parameters is real,the solution to ode45 maintains power conservation. When i change that input parameter from real to complex then ode45 solution is not maintaing power conservation. I have used relatve error tolerance = 1e-6 and absolute error tolerance = 1e-9. Please let me know what can be done to get the correct results.
For eg, In the below code, tv* parameter was initially real, which maintained power conservation, however when i change tv* to complex, the solution doesnt maintain power conservation.
options=odeset(‘RelTol’,1e-6,’AbsTol’,1e-9);
f=@(z,xx_val) -1i*[tv12*xx_val(2)*exp(1i*del_beta12*z)+tv13*xx_val(3)*exp(1i*del_beta13*z)+tv14*xx_val(4)*exp(1i*del_beta14*z)+tv15*xx_val(5)*exp(1i*del_beta15*z)+tv16*xx_val(6)*exp(1i*del_beta16*z);…
tv21*xx_val(1)*exp(1i*del_beta21*z)+tv23*xx_val(3)*exp(1i*del_beta23*z)+tv24*xx_val(4)*exp(1i*del_beta24*z)+tv25*xx_val(5)*exp(1i*del_beta25*z)+tv26*xx_val(6)*exp(1i*del_beta26*z);…
tv31*xx_val(1)*exp(1i*del_beta31*z)+tv32*xx_val(2)*exp(1i*del_beta32*z)+tv34*xx_val(4)*exp(1i*del_beta34*z)+tv35*xx_val(5)*exp(1i*del_beta35*z)+tv36*xx_val(6)*exp(1i*del_beta36*z);…
tv41*xx_val(1)*exp(1i*del_beta41*z)+tv42*xx_val(2)*exp(1i*del_beta42*z)+tv43*xx_val(3)*exp(1i*del_beta43*z)+tv45*xx_val(5)*exp(1i*del_beta45*z)+tv46*xx_val(6)*exp(1i*del_beta46*z);…
tv51*xx_val(1)*exp(1i*del_beta51*z)+tv52*xx_val(2)*exp(1i*del_beta52*z)+tv53*xx_val(3)*exp(1i*del_beta53*z)+tv54*xx_val(4)*exp(1i*del_beta54*z)+tv56*xx_val(6)*exp(1i*del_beta56*z);…
tv61*xx_val(1)*exp(1i*del_beta61*z)+tv62*xx_val(2)*exp(1i*del_beta62*z)+tv63*xx_val(3)*exp(1i*del_beta63*z)+tv64*xx_val(4)*exp(1i*del_beta64*z)+tv65*xx_val(5)*exp(1i*del_beta65*z)];
[zz,xa_var]=ode45(f,[0 1],init_condit(nn,:),options); %[LP01 LP11a] represent the initial conditionOde45 results dont maintain power conservation for some cases. How to ensure that power conservation is maintained?
While using ode45 to solve coupled differential equation, when one of the input parameters is real,the solution to ode45 maintains power conservation. When i change that input parameter from real to complex then ode45 solution is not maintaing power conservation. I have used relatve error tolerance = 1e-6 and absolute error tolerance = 1e-9. Please let me know what can be done to get the correct results.
For eg, In the below code, tv* parameter was initially real, which maintained power conservation, however when i change tv* to complex, the solution doesnt maintain power conservation.
options=odeset(‘RelTol’,1e-6,’AbsTol’,1e-9);
f=@(z,xx_val) -1i*[tv12*xx_val(2)*exp(1i*del_beta12*z)+tv13*xx_val(3)*exp(1i*del_beta13*z)+tv14*xx_val(4)*exp(1i*del_beta14*z)+tv15*xx_val(5)*exp(1i*del_beta15*z)+tv16*xx_val(6)*exp(1i*del_beta16*z);…
tv21*xx_val(1)*exp(1i*del_beta21*z)+tv23*xx_val(3)*exp(1i*del_beta23*z)+tv24*xx_val(4)*exp(1i*del_beta24*z)+tv25*xx_val(5)*exp(1i*del_beta25*z)+tv26*xx_val(6)*exp(1i*del_beta26*z);…
tv31*xx_val(1)*exp(1i*del_beta31*z)+tv32*xx_val(2)*exp(1i*del_beta32*z)+tv34*xx_val(4)*exp(1i*del_beta34*z)+tv35*xx_val(5)*exp(1i*del_beta35*z)+tv36*xx_val(6)*exp(1i*del_beta36*z);…
tv41*xx_val(1)*exp(1i*del_beta41*z)+tv42*xx_val(2)*exp(1i*del_beta42*z)+tv43*xx_val(3)*exp(1i*del_beta43*z)+tv45*xx_val(5)*exp(1i*del_beta45*z)+tv46*xx_val(6)*exp(1i*del_beta46*z);…
tv51*xx_val(1)*exp(1i*del_beta51*z)+tv52*xx_val(2)*exp(1i*del_beta52*z)+tv53*xx_val(3)*exp(1i*del_beta53*z)+tv54*xx_val(4)*exp(1i*del_beta54*z)+tv56*xx_val(6)*exp(1i*del_beta56*z);…
tv61*xx_val(1)*exp(1i*del_beta61*z)+tv62*xx_val(2)*exp(1i*del_beta62*z)+tv63*xx_val(3)*exp(1i*del_beta63*z)+tv64*xx_val(4)*exp(1i*del_beta64*z)+tv65*xx_val(5)*exp(1i*del_beta65*z)];
[zz,xa_var]=ode45(f,[0 1],init_condit(nn,:),options); %[LP01 LP11a] represent the initial condition Ode45 results dont maintain power conservation for some cases. How to ensure that power conservation is maintained?
While using ode45 to solve coupled differential equation, when one of the input parameters is real,the solution to ode45 maintains power conservation. When i change that input parameter from real to complex then ode45 solution is not maintaing power conservation. I have used relatve error tolerance = 1e-6 and absolute error tolerance = 1e-9. Please let me know what can be done to get the correct results.
For eg, In the below code, tv* parameter was initially real, which maintained power conservation, however when i change tv* to complex, the solution doesnt maintain power conservation.
options=odeset(‘RelTol’,1e-6,’AbsTol’,1e-9);
f=@(z,xx_val) -1i*[tv12*xx_val(2)*exp(1i*del_beta12*z)+tv13*xx_val(3)*exp(1i*del_beta13*z)+tv14*xx_val(4)*exp(1i*del_beta14*z)+tv15*xx_val(5)*exp(1i*del_beta15*z)+tv16*xx_val(6)*exp(1i*del_beta16*z);…
tv21*xx_val(1)*exp(1i*del_beta21*z)+tv23*xx_val(3)*exp(1i*del_beta23*z)+tv24*xx_val(4)*exp(1i*del_beta24*z)+tv25*xx_val(5)*exp(1i*del_beta25*z)+tv26*xx_val(6)*exp(1i*del_beta26*z);…
tv31*xx_val(1)*exp(1i*del_beta31*z)+tv32*xx_val(2)*exp(1i*del_beta32*z)+tv34*xx_val(4)*exp(1i*del_beta34*z)+tv35*xx_val(5)*exp(1i*del_beta35*z)+tv36*xx_val(6)*exp(1i*del_beta36*z);…
tv41*xx_val(1)*exp(1i*del_beta41*z)+tv42*xx_val(2)*exp(1i*del_beta42*z)+tv43*xx_val(3)*exp(1i*del_beta43*z)+tv45*xx_val(5)*exp(1i*del_beta45*z)+tv46*xx_val(6)*exp(1i*del_beta46*z);…
tv51*xx_val(1)*exp(1i*del_beta51*z)+tv52*xx_val(2)*exp(1i*del_beta52*z)+tv53*xx_val(3)*exp(1i*del_beta53*z)+tv54*xx_val(4)*exp(1i*del_beta54*z)+tv56*xx_val(6)*exp(1i*del_beta56*z);…
tv61*xx_val(1)*exp(1i*del_beta61*z)+tv62*xx_val(2)*exp(1i*del_beta62*z)+tv63*xx_val(3)*exp(1i*del_beta63*z)+tv64*xx_val(4)*exp(1i*del_beta64*z)+tv65*xx_val(5)*exp(1i*del_beta65*z)];
[zz,xa_var]=ode45(f,[0 1],init_condit(nn,:),options); %[LP01 LP11a] represent the initial condition ode45_error MATLAB Answers — New Questions
I have a problem involving textbook MATLAB and use of handles and functions
I’m having problems figuring out how to get some MATLAB code from a textbook to run. The code follows. The only original code statements are the first seven lines. I was trying to provide some basic data to get the code to draw a plane. I did have to add some "end" statements to the code, including the end at the bottom. I would like to get this code to draw an image and move it around a screen, but this code is supposed to do that. I need to learn how to get the code to run. I have a number of additional (or perhaps core) questions.
Is "fred" an appropriate handle reference?
Do I need to define a handle reference?
How do I call drawPlaneBody?
Can you help me to get this code (from a textbook) to work?
Thank you most sincerely.
pn = 20;
pe=0;
pd=0;
phi =0;
theta=0;
psi=0;
handle="fred";
function handle = drawPlaneBody(pn,pe,pd,phi,theta,psi,handle)
%define points on plane in local NED coordintates
NED = airplanepoints;
%rotate plane by (phi; theta; psi)
NED = rotate(NED, phi, theta, psi);
%translate plane to [pn; pe; pd]
NED = translate(NED, pn, pe, pd);
%transform vertices from NED to XYZ
R = […
0, 1, 0;…
1, 0 , 0;…
0, 0, -1;…
];
XYZ = R* NED;
%plot plane
if isempty(handle)
handle = plot3(XYZ(1,:),XYZ(2,:),XYZ(3,:),’Erasemode’, mode);
else
set(handle, ‘XData’, XYZ(1,:), ‘YData’,XYZ(2,:), ‘ZData’,XYZ(3,:));
drawnow
end
function XYZ = airplanepoints
%define points on the aircraft in local NED
coordinates
XYZ = […
0 0 0;%point1
-2 1 1;%point2
-2 1 -1;%point3
0 0 0;%point1
-2 -1 1;%point4
-2 -1 -1;%point5
0 0 0;%point1
-2 1 1;%point2
-2 -1 1;%point4
0 0 0;%point1
-2 1 -1;%point3
-2 -1 -1;%point5
0 0 0;%point1
-2 1 1;%point2
18 0 0;%point6
-2 1 -1;%point3
18 0 0;%point6
-2 -1 -1;%point5
18 0 0;%point6
-2 -1 1;%point4
18 0 0;%point6
-2 1 1;%point2
0 0 0;%point1
-5 0 0;%point7
-5 -10 0;%point8
-8 -10 0;%point9
-8 10 0;%point10
-5 10 0;%point11
-5 0 0;%point7
-15.5 0 0;%point12
-15.5 2 0;%point13
-17.5 2 0;%point14
-17.5 -2 0;%point15
-15.5 -2 0;%point16
-15.5 0 0;%point12
-18 0 0;%point6
-18 0 2;%point17
-15.5 0 0;%point15
-18 0 0;%point16
];
end
function XYZ=rotate(XYZ,phi,theta,psi)
%define rotation matrix
R_roll = [
1, 0, 0;
0, cos(phi), -sin(phi);
0, sin(phi), cos(phi)];
R_pitch = [
cos(theta), 0, sin(theta);
0, 1, 0;
-sin(theta), 0, cos(theta)];
R_yaw = [
cos(psi), -sin(psi), 0;
sin(psi), cos(psi), 0;
0, 0, 1];
R = R_roll*R_pitch*R_yaw;
%rotate vertices
XYZ =R*XYZ;
end
function XYZ = translate(XYZ, pn, pe, pd)
XYZ = XYZ + repmat([pn;pe;pd],1,size(XYZ,2));
end
endI’m having problems figuring out how to get some MATLAB code from a textbook to run. The code follows. The only original code statements are the first seven lines. I was trying to provide some basic data to get the code to draw a plane. I did have to add some "end" statements to the code, including the end at the bottom. I would like to get this code to draw an image and move it around a screen, but this code is supposed to do that. I need to learn how to get the code to run. I have a number of additional (or perhaps core) questions.
Is "fred" an appropriate handle reference?
Do I need to define a handle reference?
How do I call drawPlaneBody?
Can you help me to get this code (from a textbook) to work?
Thank you most sincerely.
pn = 20;
pe=0;
pd=0;
phi =0;
theta=0;
psi=0;
handle="fred";
function handle = drawPlaneBody(pn,pe,pd,phi,theta,psi,handle)
%define points on plane in local NED coordintates
NED = airplanepoints;
%rotate plane by (phi; theta; psi)
NED = rotate(NED, phi, theta, psi);
%translate plane to [pn; pe; pd]
NED = translate(NED, pn, pe, pd);
%transform vertices from NED to XYZ
R = […
0, 1, 0;…
1, 0 , 0;…
0, 0, -1;…
];
XYZ = R* NED;
%plot plane
if isempty(handle)
handle = plot3(XYZ(1,:),XYZ(2,:),XYZ(3,:),’Erasemode’, mode);
else
set(handle, ‘XData’, XYZ(1,:), ‘YData’,XYZ(2,:), ‘ZData’,XYZ(3,:));
drawnow
end
function XYZ = airplanepoints
%define points on the aircraft in local NED
coordinates
XYZ = […
0 0 0;%point1
-2 1 1;%point2
-2 1 -1;%point3
0 0 0;%point1
-2 -1 1;%point4
-2 -1 -1;%point5
0 0 0;%point1
-2 1 1;%point2
-2 -1 1;%point4
0 0 0;%point1
-2 1 -1;%point3
-2 -1 -1;%point5
0 0 0;%point1
-2 1 1;%point2
18 0 0;%point6
-2 1 -1;%point3
18 0 0;%point6
-2 -1 -1;%point5
18 0 0;%point6
-2 -1 1;%point4
18 0 0;%point6
-2 1 1;%point2
0 0 0;%point1
-5 0 0;%point7
-5 -10 0;%point8
-8 -10 0;%point9
-8 10 0;%point10
-5 10 0;%point11
-5 0 0;%point7
-15.5 0 0;%point12
-15.5 2 0;%point13
-17.5 2 0;%point14
-17.5 -2 0;%point15
-15.5 -2 0;%point16
-15.5 0 0;%point12
-18 0 0;%point6
-18 0 2;%point17
-15.5 0 0;%point15
-18 0 0;%point16
];
end
function XYZ=rotate(XYZ,phi,theta,psi)
%define rotation matrix
R_roll = [
1, 0, 0;
0, cos(phi), -sin(phi);
0, sin(phi), cos(phi)];
R_pitch = [
cos(theta), 0, sin(theta);
0, 1, 0;
-sin(theta), 0, cos(theta)];
R_yaw = [
cos(psi), -sin(psi), 0;
sin(psi), cos(psi), 0;
0, 0, 1];
R = R_roll*R_pitch*R_yaw;
%rotate vertices
XYZ =R*XYZ;
end
function XYZ = translate(XYZ, pn, pe, pd)
XYZ = XYZ + repmat([pn;pe;pd],1,size(XYZ,2));
end
end I’m having problems figuring out how to get some MATLAB code from a textbook to run. The code follows. The only original code statements are the first seven lines. I was trying to provide some basic data to get the code to draw a plane. I did have to add some "end" statements to the code, including the end at the bottom. I would like to get this code to draw an image and move it around a screen, but this code is supposed to do that. I need to learn how to get the code to run. I have a number of additional (or perhaps core) questions.
Is "fred" an appropriate handle reference?
Do I need to define a handle reference?
How do I call drawPlaneBody?
Can you help me to get this code (from a textbook) to work?
Thank you most sincerely.
pn = 20;
pe=0;
pd=0;
phi =0;
theta=0;
psi=0;
handle="fred";
function handle = drawPlaneBody(pn,pe,pd,phi,theta,psi,handle)
%define points on plane in local NED coordintates
NED = airplanepoints;
%rotate plane by (phi; theta; psi)
NED = rotate(NED, phi, theta, psi);
%translate plane to [pn; pe; pd]
NED = translate(NED, pn, pe, pd);
%transform vertices from NED to XYZ
R = […
0, 1, 0;…
1, 0 , 0;…
0, 0, -1;…
];
XYZ = R* NED;
%plot plane
if isempty(handle)
handle = plot3(XYZ(1,:),XYZ(2,:),XYZ(3,:),’Erasemode’, mode);
else
set(handle, ‘XData’, XYZ(1,:), ‘YData’,XYZ(2,:), ‘ZData’,XYZ(3,:));
drawnow
end
function XYZ = airplanepoints
%define points on the aircraft in local NED
coordinates
XYZ = […
0 0 0;%point1
-2 1 1;%point2
-2 1 -1;%point3
0 0 0;%point1
-2 -1 1;%point4
-2 -1 -1;%point5
0 0 0;%point1
-2 1 1;%point2
-2 -1 1;%point4
0 0 0;%point1
-2 1 -1;%point3
-2 -1 -1;%point5
0 0 0;%point1
-2 1 1;%point2
18 0 0;%point6
-2 1 -1;%point3
18 0 0;%point6
-2 -1 -1;%point5
18 0 0;%point6
-2 -1 1;%point4
18 0 0;%point6
-2 1 1;%point2
0 0 0;%point1
-5 0 0;%point7
-5 -10 0;%point8
-8 -10 0;%point9
-8 10 0;%point10
-5 10 0;%point11
-5 0 0;%point7
-15.5 0 0;%point12
-15.5 2 0;%point13
-17.5 2 0;%point14
-17.5 -2 0;%point15
-15.5 -2 0;%point16
-15.5 0 0;%point12
-18 0 0;%point6
-18 0 2;%point17
-15.5 0 0;%point15
-18 0 0;%point16
];
end
function XYZ=rotate(XYZ,phi,theta,psi)
%define rotation matrix
R_roll = [
1, 0, 0;
0, cos(phi), -sin(phi);
0, sin(phi), cos(phi)];
R_pitch = [
cos(theta), 0, sin(theta);
0, 1, 0;
-sin(theta), 0, cos(theta)];
R_yaw = [
cos(psi), -sin(psi), 0;
sin(psi), cos(psi), 0;
0, 0, 1];
R = R_roll*R_pitch*R_yaw;
%rotate vertices
XYZ =R*XYZ;
end
function XYZ = translate(XYZ, pn, pe, pd)
XYZ = XYZ + repmat([pn;pe;pd],1,size(XYZ,2));
end
end handle, matlab function, how to use functions MATLAB Answers — New Questions
Is there a “once” function?
Hi all,
I have an array of objects that should each have a property _serverDir_ set. Setting this property requires a little bit of effort and computation time (checking folders etc).
When I put this logic inside a "Dependent = True" property of my class, this logic is run on *every* object in my array of objects.
Is there a natural location to store the _serverDir_ information so that it only gets run *once* by the first object that requests this property, and each subsequent object re-uses this result?
Thanks,
Sven.Hi all,
I have an array of objects that should each have a property _serverDir_ set. Setting this property requires a little bit of effort and computation time (checking folders etc).
When I put this logic inside a "Dependent = True" property of my class, this logic is run on *every* object in my array of objects.
Is there a natural location to store the _serverDir_ information so that it only gets run *once* by the first object that requests this property, and each subsequent object re-uses this result?
Thanks,
Sven. Hi all,
I have an array of objects that should each have a property _serverDir_ set. Setting this property requires a little bit of effort and computation time (checking folders etc).
When I put this logic inside a "Dependent = True" property of my class, this logic is run on *every* object in my array of objects.
Is there a natural location to store the _serverDir_ information so that it only gets run *once* by the first object that requests this property, and each subsequent object re-uses this result?
Thanks,
Sven. static property, once MATLAB Answers — New Questions
Fitting not working or bad fit
% Define the data
dr_data = [2.5453, 0.042123; 5.0907, 0.075326; 7.636, 0.059506; 10.1813, 0.071553; 12.7267, 0.071365; 15.272, 0.067195; 17.8173, 0.046372; 20.3627, 0.043397; 22.908, 0.017179; 25.4533, -0.0063329; 27.9987, -0.030789; 30.544, -0.047569; 33.0893, -0.089512; 35.6347, -0.080675; 38.18, -0.089138; 40.7253, -0.1102; 43.2707, -0.12061; 45.816, -0.11857; 48.3613, -0.11955; 50.9067, -0.10803; 53.452, -0.10462; 55.9973, -0.099548; 58.5427, -0.097164; 61.088, -0.09994; 63.6333, -0.077017; 66.1787, -0.062839; 68.724, -0.048422; 71.2693, -0.03686; 73.8147, -0.01469; 76.3, 0];
dtheta_data = [2.5453, -0.099251; 5.0907, -0.16064; 7.636, -0.21858; 10.1813, -0.18965; 12.7267, -0.16996; 15.272, -0.18172; 17.8173, -0.15029; 20.3627, -0.12541; 22.908, -0.082786; 25.4533, -0.0071716; 27.9987, 0.03695; 30.544, 0.089002; 33.0893, 0.12873; 35.6347, 0.13092; 38.18, 0.13908; 40.7253, 0.17211; 43.2707, 0.16686; 45.816, 0.15826; 48.3613, 0.14872; 50.9067, 0.15295; 53.452, 0.12677; 55.9973, 0.10964; 58.5427, 0.10223; 61.088, 0.10951; 63.6333, 0.088493; 66.1787, 0.068903; 68.724, 0.054396; 71.2693, 0.035731; 73.8147, 0.030172; 76.3, 0];
% Define the function for the differential equations
function dydr = odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R)
dydr = zeros(4,1);
dydr(1) = y(2);
dydr(2) = -((lambda_init+1)*y(2)+1/r*(kappa_init*r^2*cos(theta_k_init)-(lambda_init+1))*y(1)-kappa_init*r*y(3)*sin(theta_k_init)+16*lambda_init*r^2/(c^4*R^2))/(r*(lambda_init+1));
dydr(3) = y(4);
dydr(4) = -(y(4)+1/r*(kappa_init*r^2*cos(theta_k_init)-1)*y(3)+kappa_init*r*y(1)*sin(theta_k_init))/r;
end
% Boundary conditions
function res = bcfun(ya, yb, ya1, ya3, yb1, yb3)
res = [ya(1)-ya1; ya(3)-ya3; yb(1)-yb1; yb(3)-yb3];
end
% Define the function to compute residuals
function residuals = compute_residuals(params, dr_data, dtheta_data, rout, R_init)
lambda_init = params(1);
kappa_init = params(2);
theta_k_init = params(3);
ya1 = params(4); % Boundary condition parameter ya(1)
ya3 = params(5); % Boundary condition parameter ya(3)
yb1 = params(6); % Boundary condition parameter yb(1)
yb3 = params(7); % Boundary condition parameter
c = sqrt(4 – (rout/R_init)^2);
R_init = 2000; % Initial value of R
rout = 76.3; % Max value of r
% Adjust the number of points for interpolation
num_points = size(dr_data, 1);
solinit = bvpinit(linspace(0.0001, rout, num_points), [ya1, 0, ya3, 0]);
sol = bvp4c(@(r, y) odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R_init), @(ya, yb) bcfun(ya, yb, ya1, ya3, yb1, yb3), solinit);
r = linspace(0.0001, rout, num_points);
y = deval(sol, r);
dr_sol = y(1,:);
dtheta_sol = y(3,:);
% Ensure that arrays have compatible sizes
dr_residuals = dr_data(:, 2) – dr_sol;
dtheta_residuals = dtheta_data(:, 2) – dtheta_sol;
residuals = [dr_residuals; dtheta_residuals];
end
% Initial guess for the parameters
params_init = [2.1, 0.03, 0.004, 0, 0, 0, 0]; % Initial guess for parameters including boundary conditions
% Bounds for parameters
lb = [1, 0.001, 0, -Inf, -Inf, -Inf, -Inf]; % Lower bounds for lambda, kappa, theta_k, ya1, ya3, yb1, yb3
ub = [3, 0.5, pi/2, Inf, Inf, Inf, Inf]; % Upper bounds for lambda, kappa, theta_k, ya1, ya3, yb1, yb3
% Perform optimization
params_opt = lsqnonlin(@(params) compute_residuals(params, dr_data, dtheta_data, rout, R_init), params_init, lb, ub);
% Extract optimized parameters
lambda_opt = params_opt(1);
kappa_opt = params_opt(2);
theta_k_opt = params_opt(3);
ya1_opt = params_opt(4);
ya3_opt = params_opt(5);
yb1_opt = params_opt(6);
yb3_opt = params_opt(7);
% Display optimized parameters
disp([‘Optimized lambda: ‘, num2str(lambda_opt)]);
disp([‘Optimized kappa: ‘, num2str(kappa_opt)]);
disp([‘Optimized theta_k: ‘, num2str(theta_k_opt)]);
disp([‘Optimized ya1: ‘, num2str(ya1_opt)]);
disp([‘Optimized ya3: ‘, num2str(ya3_opt)]);
disp([‘Optimized yb1: ‘, num2str(yb1_opt)]);
disp([‘Optimized yb3: ‘, num2str(yb3_opt)]);
% Plot the solutions using optimized parameters
lambda_init = lambda_opt;
kappa_init = kappa_opt;
theta_k_init = theta_k_opt;
ya1 = ya1_opt;
ya3 = ya3_opt;
yb1 = yb1_opt;
yb3 = yb3_opt;
c = sqrt(4 – (rout/R_init)^2);
num_points = size(dr_data, 1);
solinit = bvpinit(linspace(0.0001, rout, num_points), [ya1, yb1, ya3, yb3]);
sol = bvp4c(@(r, y) odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R_init), @(ya, yb) bcfun(ya, yb, ya1, ya3, yb1, yb3), solinit);
r = linspace(0.0001, rout, num_points);
y = deval(sol, r);
dr_sol = y(1,:);
dtheta_sol = y(3,:);
% Plot the solutions
figure;
subplot(2,1,1);
plot(r, dr_sol, ‘b-‘, dr_data(:,1), dr_data(:,2), ‘ro’);
xlabel(‘r’);
ylabel(‘dr(r)’);
title(‘Solution of dr(r) vs r’);
legend(‘Fitted Solution’, ‘Data’);
subplot(2,1,2);
plot(r, dtheta_sol, ‘b-‘, dtheta_data(:,1), dtheta_data(:,2), ‘ro’);
xlabel(‘r’);
ylabel(‘dtheta(r)’);
title(‘Solution of dtheta(r) vs r’);
legend(‘Fitted Solution’, ‘Data’);
Now, I want to fit the simulated d_r(r) vs r and d_theta(r) vs r values with the above mentioned coupled differential eqns by usuing the fitting parameters lamda, kappa, theta_k. For the sake of good fitting one can use boundary conditions as parameter. However getting errors. Please help me to solve those errors and fitting those data.% Define the data
dr_data = [2.5453, 0.042123; 5.0907, 0.075326; 7.636, 0.059506; 10.1813, 0.071553; 12.7267, 0.071365; 15.272, 0.067195; 17.8173, 0.046372; 20.3627, 0.043397; 22.908, 0.017179; 25.4533, -0.0063329; 27.9987, -0.030789; 30.544, -0.047569; 33.0893, -0.089512; 35.6347, -0.080675; 38.18, -0.089138; 40.7253, -0.1102; 43.2707, -0.12061; 45.816, -0.11857; 48.3613, -0.11955; 50.9067, -0.10803; 53.452, -0.10462; 55.9973, -0.099548; 58.5427, -0.097164; 61.088, -0.09994; 63.6333, -0.077017; 66.1787, -0.062839; 68.724, -0.048422; 71.2693, -0.03686; 73.8147, -0.01469; 76.3, 0];
dtheta_data = [2.5453, -0.099251; 5.0907, -0.16064; 7.636, -0.21858; 10.1813, -0.18965; 12.7267, -0.16996; 15.272, -0.18172; 17.8173, -0.15029; 20.3627, -0.12541; 22.908, -0.082786; 25.4533, -0.0071716; 27.9987, 0.03695; 30.544, 0.089002; 33.0893, 0.12873; 35.6347, 0.13092; 38.18, 0.13908; 40.7253, 0.17211; 43.2707, 0.16686; 45.816, 0.15826; 48.3613, 0.14872; 50.9067, 0.15295; 53.452, 0.12677; 55.9973, 0.10964; 58.5427, 0.10223; 61.088, 0.10951; 63.6333, 0.088493; 66.1787, 0.068903; 68.724, 0.054396; 71.2693, 0.035731; 73.8147, 0.030172; 76.3, 0];
% Define the function for the differential equations
function dydr = odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R)
dydr = zeros(4,1);
dydr(1) = y(2);
dydr(2) = -((lambda_init+1)*y(2)+1/r*(kappa_init*r^2*cos(theta_k_init)-(lambda_init+1))*y(1)-kappa_init*r*y(3)*sin(theta_k_init)+16*lambda_init*r^2/(c^4*R^2))/(r*(lambda_init+1));
dydr(3) = y(4);
dydr(4) = -(y(4)+1/r*(kappa_init*r^2*cos(theta_k_init)-1)*y(3)+kappa_init*r*y(1)*sin(theta_k_init))/r;
end
% Boundary conditions
function res = bcfun(ya, yb, ya1, ya3, yb1, yb3)
res = [ya(1)-ya1; ya(3)-ya3; yb(1)-yb1; yb(3)-yb3];
end
% Define the function to compute residuals
function residuals = compute_residuals(params, dr_data, dtheta_data, rout, R_init)
lambda_init = params(1);
kappa_init = params(2);
theta_k_init = params(3);
ya1 = params(4); % Boundary condition parameter ya(1)
ya3 = params(5); % Boundary condition parameter ya(3)
yb1 = params(6); % Boundary condition parameter yb(1)
yb3 = params(7); % Boundary condition parameter
c = sqrt(4 – (rout/R_init)^2);
R_init = 2000; % Initial value of R
rout = 76.3; % Max value of r
% Adjust the number of points for interpolation
num_points = size(dr_data, 1);
solinit = bvpinit(linspace(0.0001, rout, num_points), [ya1, 0, ya3, 0]);
sol = bvp4c(@(r, y) odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R_init), @(ya, yb) bcfun(ya, yb, ya1, ya3, yb1, yb3), solinit);
r = linspace(0.0001, rout, num_points);
y = deval(sol, r);
dr_sol = y(1,:);
dtheta_sol = y(3,:);
% Ensure that arrays have compatible sizes
dr_residuals = dr_data(:, 2) – dr_sol;
dtheta_residuals = dtheta_data(:, 2) – dtheta_sol;
residuals = [dr_residuals; dtheta_residuals];
end
% Initial guess for the parameters
params_init = [2.1, 0.03, 0.004, 0, 0, 0, 0]; % Initial guess for parameters including boundary conditions
% Bounds for parameters
lb = [1, 0.001, 0, -Inf, -Inf, -Inf, -Inf]; % Lower bounds for lambda, kappa, theta_k, ya1, ya3, yb1, yb3
ub = [3, 0.5, pi/2, Inf, Inf, Inf, Inf]; % Upper bounds for lambda, kappa, theta_k, ya1, ya3, yb1, yb3
% Perform optimization
params_opt = lsqnonlin(@(params) compute_residuals(params, dr_data, dtheta_data, rout, R_init), params_init, lb, ub);
% Extract optimized parameters
lambda_opt = params_opt(1);
kappa_opt = params_opt(2);
theta_k_opt = params_opt(3);
ya1_opt = params_opt(4);
ya3_opt = params_opt(5);
yb1_opt = params_opt(6);
yb3_opt = params_opt(7);
% Display optimized parameters
disp([‘Optimized lambda: ‘, num2str(lambda_opt)]);
disp([‘Optimized kappa: ‘, num2str(kappa_opt)]);
disp([‘Optimized theta_k: ‘, num2str(theta_k_opt)]);
disp([‘Optimized ya1: ‘, num2str(ya1_opt)]);
disp([‘Optimized ya3: ‘, num2str(ya3_opt)]);
disp([‘Optimized yb1: ‘, num2str(yb1_opt)]);
disp([‘Optimized yb3: ‘, num2str(yb3_opt)]);
% Plot the solutions using optimized parameters
lambda_init = lambda_opt;
kappa_init = kappa_opt;
theta_k_init = theta_k_opt;
ya1 = ya1_opt;
ya3 = ya3_opt;
yb1 = yb1_opt;
yb3 = yb3_opt;
c = sqrt(4 – (rout/R_init)^2);
num_points = size(dr_data, 1);
solinit = bvpinit(linspace(0.0001, rout, num_points), [ya1, yb1, ya3, yb3]);
sol = bvp4c(@(r, y) odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R_init), @(ya, yb) bcfun(ya, yb, ya1, ya3, yb1, yb3), solinit);
r = linspace(0.0001, rout, num_points);
y = deval(sol, r);
dr_sol = y(1,:);
dtheta_sol = y(3,:);
% Plot the solutions
figure;
subplot(2,1,1);
plot(r, dr_sol, ‘b-‘, dr_data(:,1), dr_data(:,2), ‘ro’);
xlabel(‘r’);
ylabel(‘dr(r)’);
title(‘Solution of dr(r) vs r’);
legend(‘Fitted Solution’, ‘Data’);
subplot(2,1,2);
plot(r, dtheta_sol, ‘b-‘, dtheta_data(:,1), dtheta_data(:,2), ‘ro’);
xlabel(‘r’);
ylabel(‘dtheta(r)’);
title(‘Solution of dtheta(r) vs r’);
legend(‘Fitted Solution’, ‘Data’);
Now, I want to fit the simulated d_r(r) vs r and d_theta(r) vs r values with the above mentioned coupled differential eqns by usuing the fitting parameters lamda, kappa, theta_k. For the sake of good fitting one can use boundary conditions as parameter. However getting errors. Please help me to solve those errors and fitting those data. % Define the data
dr_data = [2.5453, 0.042123; 5.0907, 0.075326; 7.636, 0.059506; 10.1813, 0.071553; 12.7267, 0.071365; 15.272, 0.067195; 17.8173, 0.046372; 20.3627, 0.043397; 22.908, 0.017179; 25.4533, -0.0063329; 27.9987, -0.030789; 30.544, -0.047569; 33.0893, -0.089512; 35.6347, -0.080675; 38.18, -0.089138; 40.7253, -0.1102; 43.2707, -0.12061; 45.816, -0.11857; 48.3613, -0.11955; 50.9067, -0.10803; 53.452, -0.10462; 55.9973, -0.099548; 58.5427, -0.097164; 61.088, -0.09994; 63.6333, -0.077017; 66.1787, -0.062839; 68.724, -0.048422; 71.2693, -0.03686; 73.8147, -0.01469; 76.3, 0];
dtheta_data = [2.5453, -0.099251; 5.0907, -0.16064; 7.636, -0.21858; 10.1813, -0.18965; 12.7267, -0.16996; 15.272, -0.18172; 17.8173, -0.15029; 20.3627, -0.12541; 22.908, -0.082786; 25.4533, -0.0071716; 27.9987, 0.03695; 30.544, 0.089002; 33.0893, 0.12873; 35.6347, 0.13092; 38.18, 0.13908; 40.7253, 0.17211; 43.2707, 0.16686; 45.816, 0.15826; 48.3613, 0.14872; 50.9067, 0.15295; 53.452, 0.12677; 55.9973, 0.10964; 58.5427, 0.10223; 61.088, 0.10951; 63.6333, 0.088493; 66.1787, 0.068903; 68.724, 0.054396; 71.2693, 0.035731; 73.8147, 0.030172; 76.3, 0];
% Define the function for the differential equations
function dydr = odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R)
dydr = zeros(4,1);
dydr(1) = y(2);
dydr(2) = -((lambda_init+1)*y(2)+1/r*(kappa_init*r^2*cos(theta_k_init)-(lambda_init+1))*y(1)-kappa_init*r*y(3)*sin(theta_k_init)+16*lambda_init*r^2/(c^4*R^2))/(r*(lambda_init+1));
dydr(3) = y(4);
dydr(4) = -(y(4)+1/r*(kappa_init*r^2*cos(theta_k_init)-1)*y(3)+kappa_init*r*y(1)*sin(theta_k_init))/r;
end
% Boundary conditions
function res = bcfun(ya, yb, ya1, ya3, yb1, yb3)
res = [ya(1)-ya1; ya(3)-ya3; yb(1)-yb1; yb(3)-yb3];
end
% Define the function to compute residuals
function residuals = compute_residuals(params, dr_data, dtheta_data, rout, R_init)
lambda_init = params(1);
kappa_init = params(2);
theta_k_init = params(3);
ya1 = params(4); % Boundary condition parameter ya(1)
ya3 = params(5); % Boundary condition parameter ya(3)
yb1 = params(6); % Boundary condition parameter yb(1)
yb3 = params(7); % Boundary condition parameter
c = sqrt(4 – (rout/R_init)^2);
R_init = 2000; % Initial value of R
rout = 76.3; % Max value of r
% Adjust the number of points for interpolation
num_points = size(dr_data, 1);
solinit = bvpinit(linspace(0.0001, rout, num_points), [ya1, 0, ya3, 0]);
sol = bvp4c(@(r, y) odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R_init), @(ya, yb) bcfun(ya, yb, ya1, ya3, yb1, yb3), solinit);
r = linspace(0.0001, rout, num_points);
y = deval(sol, r);
dr_sol = y(1,:);
dtheta_sol = y(3,:);
% Ensure that arrays have compatible sizes
dr_residuals = dr_data(:, 2) – dr_sol;
dtheta_residuals = dtheta_data(:, 2) – dtheta_sol;
residuals = [dr_residuals; dtheta_residuals];
end
% Initial guess for the parameters
params_init = [2.1, 0.03, 0.004, 0, 0, 0, 0]; % Initial guess for parameters including boundary conditions
% Bounds for parameters
lb = [1, 0.001, 0, -Inf, -Inf, -Inf, -Inf]; % Lower bounds for lambda, kappa, theta_k, ya1, ya3, yb1, yb3
ub = [3, 0.5, pi/2, Inf, Inf, Inf, Inf]; % Upper bounds for lambda, kappa, theta_k, ya1, ya3, yb1, yb3
% Perform optimization
params_opt = lsqnonlin(@(params) compute_residuals(params, dr_data, dtheta_data, rout, R_init), params_init, lb, ub);
% Extract optimized parameters
lambda_opt = params_opt(1);
kappa_opt = params_opt(2);
theta_k_opt = params_opt(3);
ya1_opt = params_opt(4);
ya3_opt = params_opt(5);
yb1_opt = params_opt(6);
yb3_opt = params_opt(7);
% Display optimized parameters
disp([‘Optimized lambda: ‘, num2str(lambda_opt)]);
disp([‘Optimized kappa: ‘, num2str(kappa_opt)]);
disp([‘Optimized theta_k: ‘, num2str(theta_k_opt)]);
disp([‘Optimized ya1: ‘, num2str(ya1_opt)]);
disp([‘Optimized ya3: ‘, num2str(ya3_opt)]);
disp([‘Optimized yb1: ‘, num2str(yb1_opt)]);
disp([‘Optimized yb3: ‘, num2str(yb3_opt)]);
% Plot the solutions using optimized parameters
lambda_init = lambda_opt;
kappa_init = kappa_opt;
theta_k_init = theta_k_opt;
ya1 = ya1_opt;
ya3 = ya3_opt;
yb1 = yb1_opt;
yb3 = yb3_opt;
c = sqrt(4 – (rout/R_init)^2);
num_points = size(dr_data, 1);
solinit = bvpinit(linspace(0.0001, rout, num_points), [ya1, yb1, ya3, yb3]);
sol = bvp4c(@(r, y) odefun(r, y, lambda_init, kappa_init, theta_k_init, c, R_init), @(ya, yb) bcfun(ya, yb, ya1, ya3, yb1, yb3), solinit);
r = linspace(0.0001, rout, num_points);
y = deval(sol, r);
dr_sol = y(1,:);
dtheta_sol = y(3,:);
% Plot the solutions
figure;
subplot(2,1,1);
plot(r, dr_sol, ‘b-‘, dr_data(:,1), dr_data(:,2), ‘ro’);
xlabel(‘r’);
ylabel(‘dr(r)’);
title(‘Solution of dr(r) vs r’);
legend(‘Fitted Solution’, ‘Data’);
subplot(2,1,2);
plot(r, dtheta_sol, ‘b-‘, dtheta_data(:,1), dtheta_data(:,2), ‘ro’);
xlabel(‘r’);
ylabel(‘dtheta(r)’);
title(‘Solution of dtheta(r) vs r’);
legend(‘Fitted Solution’, ‘Data’);
Now, I want to fit the simulated d_r(r) vs r and d_theta(r) vs r values with the above mentioned coupled differential eqns by usuing the fitting parameters lamda, kappa, theta_k. For the sake of good fitting one can use boundary conditions as parameter. However getting errors. Please help me to solve those errors and fitting those data. curve fitting MATLAB Answers — New Questions
Matlab Warning: Solver not applicable (mosek)
Matlab + yalmip toolbox, when calling cplex or mosek to solve the optimization problem, the result is always wrong: Warning: Solver not applicable (mosek), Warning: Solver not applicable (cplex), I think my software is installed correctly, Now I have several reasons for doubt:
1. Too many constraints, the scale of problem solving is too large
2. The software version does not match?(matlab2014b+mosek 8.0.0.60/cplex 12.6.3)
3. There are some mistakes in the code or there is no feasible solution (I think it is unlikely)
Please help me see what to do,thank you !
Code for solving part:
ops=sdpsettings
ops = sdpsettings(‘verbose’,2,’solver’,’mosek’,’fmincon.MaxFunEvals’,30000);
sol =solvesdp(Constraint,f,ops,’full’);
if sol.problem== 0
value(f)
else
disp(‘求解过程中出错’);
operation result:
ops =
solver: ”
verbose: 1
debug: 0
usex0: 0
warning: 1
cachesolvers: 0
showprogress: 0
saveduals: 1
removeequalities: 0
savesolveroutput: 0
savesolverinput: 0
saveyalmipmodel: 0
convertconvexquad: 1
assertgpnonnegativity: 1
thisisnotagp: 0
radius: Inf
relax: 0
dualize: 0
savedebug: 0
expand: 1
allowmilp: 1
allownonconvex: 1
shift: 0
dimacs: 0
beeponproblem: [-5 -4 -3 -2 -1]
bisection: [1×1 struct]
bilevel: [1×1 struct]
bmibnb: [1×1 struct]
bnb: [1×1 struct]
cutsdp: [1×1 struct]
kkt: [1×1 struct]
moment: [1×1 struct]
mp: [1×1 struct]
mpcvx: [1×1 struct]
plot: [1×1 struct]
robust: [1×1 struct]
sos: [1×1 struct]
refiner: [1×1 struct]
baron: []
bintprog: [1×1 struct]
bonmin: []
cdcs: [1×1 struct]
cdd: [1×1 struct]
cbc: [1×1 struct]
clp: [1×1 struct]
cplex: [1×1 struct]
csdp: [1×1 struct]
dsdp: [1×1 struct]
ecos: []
filtersd: [1×1 struct]
fmincon: [1×1 struct]
fminsearch: [1×1 struct]
frlib: [1×1 struct]
glpk: [1×1 struct]
gurobi: [1×1 struct]
ipopt: [1×1 struct]
intlinprog: [1×1 optim.options.Intlinprog]
knitro: [1×1 struct]
linprog: [1×1 struct]
lmilab: [1×1 struct]
lmirank: [1×1 struct]
logdetppa: [1×1 struct]
lpsolve: [1×1 struct]
lsqnonneg: [1×1 struct]
lsqlin: [1×1 struct]
kypd: [1×1 struct]
nag: [1×1 struct]
mosek: [1×1 struct]
nomad: []
ooqp: []
penbmi: [1×1 struct]
penlab: []
pensdp: [1×1 struct]
pop: [1×1 struct]
qpoases: []
osqp: []
qsopt: [1×1 struct]
quadprog: [1×1 struct]
quadprogbb: [1×1 struct]
scip: []
scs: [1×1 struct]
sdpa: [1×1 struct]
sdplr: [1×1 struct]
sdpt3: [1×1 struct]
sdpnal: [1×1 struct]
sedumi: [1×1 struct]
sparsepop: [1×1 struct]
sparsecolo: [1×1 struct]
vsdp: [1×1 struct]
xpress: []
Warning: Solver not applicable (mosek)
求解过程中出错
>>Matlab + yalmip toolbox, when calling cplex or mosek to solve the optimization problem, the result is always wrong: Warning: Solver not applicable (mosek), Warning: Solver not applicable (cplex), I think my software is installed correctly, Now I have several reasons for doubt:
1. Too many constraints, the scale of problem solving is too large
2. The software version does not match?(matlab2014b+mosek 8.0.0.60/cplex 12.6.3)
3. There are some mistakes in the code or there is no feasible solution (I think it is unlikely)
Please help me see what to do,thank you !
Code for solving part:
ops=sdpsettings
ops = sdpsettings(‘verbose’,2,’solver’,’mosek’,’fmincon.MaxFunEvals’,30000);
sol =solvesdp(Constraint,f,ops,’full’);
if sol.problem== 0
value(f)
else
disp(‘求解过程中出错’);
operation result:
ops =
solver: ”
verbose: 1
debug: 0
usex0: 0
warning: 1
cachesolvers: 0
showprogress: 0
saveduals: 1
removeequalities: 0
savesolveroutput: 0
savesolverinput: 0
saveyalmipmodel: 0
convertconvexquad: 1
assertgpnonnegativity: 1
thisisnotagp: 0
radius: Inf
relax: 0
dualize: 0
savedebug: 0
expand: 1
allowmilp: 1
allownonconvex: 1
shift: 0
dimacs: 0
beeponproblem: [-5 -4 -3 -2 -1]
bisection: [1×1 struct]
bilevel: [1×1 struct]
bmibnb: [1×1 struct]
bnb: [1×1 struct]
cutsdp: [1×1 struct]
kkt: [1×1 struct]
moment: [1×1 struct]
mp: [1×1 struct]
mpcvx: [1×1 struct]
plot: [1×1 struct]
robust: [1×1 struct]
sos: [1×1 struct]
refiner: [1×1 struct]
baron: []
bintprog: [1×1 struct]
bonmin: []
cdcs: [1×1 struct]
cdd: [1×1 struct]
cbc: [1×1 struct]
clp: [1×1 struct]
cplex: [1×1 struct]
csdp: [1×1 struct]
dsdp: [1×1 struct]
ecos: []
filtersd: [1×1 struct]
fmincon: [1×1 struct]
fminsearch: [1×1 struct]
frlib: [1×1 struct]
glpk: [1×1 struct]
gurobi: [1×1 struct]
ipopt: [1×1 struct]
intlinprog: [1×1 optim.options.Intlinprog]
knitro: [1×1 struct]
linprog: [1×1 struct]
lmilab: [1×1 struct]
lmirank: [1×1 struct]
logdetppa: [1×1 struct]
lpsolve: [1×1 struct]
lsqnonneg: [1×1 struct]
lsqlin: [1×1 struct]
kypd: [1×1 struct]
nag: [1×1 struct]
mosek: [1×1 struct]
nomad: []
ooqp: []
penbmi: [1×1 struct]
penlab: []
pensdp: [1×1 struct]
pop: [1×1 struct]
qpoases: []
osqp: []
qsopt: [1×1 struct]
quadprog: [1×1 struct]
quadprogbb: [1×1 struct]
scip: []
scs: [1×1 struct]
sdpa: [1×1 struct]
sdplr: [1×1 struct]
sdpt3: [1×1 struct]
sdpnal: [1×1 struct]
sedumi: [1×1 struct]
sparsepop: [1×1 struct]
sparsecolo: [1×1 struct]
vsdp: [1×1 struct]
xpress: []
Warning: Solver not applicable (mosek)
求解过程中出错
>> Matlab + yalmip toolbox, when calling cplex or mosek to solve the optimization problem, the result is always wrong: Warning: Solver not applicable (mosek), Warning: Solver not applicable (cplex), I think my software is installed correctly, Now I have several reasons for doubt:
1. Too many constraints, the scale of problem solving is too large
2. The software version does not match?(matlab2014b+mosek 8.0.0.60/cplex 12.6.3)
3. There are some mistakes in the code or there is no feasible solution (I think it is unlikely)
Please help me see what to do,thank you !
Code for solving part:
ops=sdpsettings
ops = sdpsettings(‘verbose’,2,’solver’,’mosek’,’fmincon.MaxFunEvals’,30000);
sol =solvesdp(Constraint,f,ops,’full’);
if sol.problem== 0
value(f)
else
disp(‘求解过程中出错’);
operation result:
ops =
solver: ”
verbose: 1
debug: 0
usex0: 0
warning: 1
cachesolvers: 0
showprogress: 0
saveduals: 1
removeequalities: 0
savesolveroutput: 0
savesolverinput: 0
saveyalmipmodel: 0
convertconvexquad: 1
assertgpnonnegativity: 1
thisisnotagp: 0
radius: Inf
relax: 0
dualize: 0
savedebug: 0
expand: 1
allowmilp: 1
allownonconvex: 1
shift: 0
dimacs: 0
beeponproblem: [-5 -4 -3 -2 -1]
bisection: [1×1 struct]
bilevel: [1×1 struct]
bmibnb: [1×1 struct]
bnb: [1×1 struct]
cutsdp: [1×1 struct]
kkt: [1×1 struct]
moment: [1×1 struct]
mp: [1×1 struct]
mpcvx: [1×1 struct]
plot: [1×1 struct]
robust: [1×1 struct]
sos: [1×1 struct]
refiner: [1×1 struct]
baron: []
bintprog: [1×1 struct]
bonmin: []
cdcs: [1×1 struct]
cdd: [1×1 struct]
cbc: [1×1 struct]
clp: [1×1 struct]
cplex: [1×1 struct]
csdp: [1×1 struct]
dsdp: [1×1 struct]
ecos: []
filtersd: [1×1 struct]
fmincon: [1×1 struct]
fminsearch: [1×1 struct]
frlib: [1×1 struct]
glpk: [1×1 struct]
gurobi: [1×1 struct]
ipopt: [1×1 struct]
intlinprog: [1×1 optim.options.Intlinprog]
knitro: [1×1 struct]
linprog: [1×1 struct]
lmilab: [1×1 struct]
lmirank: [1×1 struct]
logdetppa: [1×1 struct]
lpsolve: [1×1 struct]
lsqnonneg: [1×1 struct]
lsqlin: [1×1 struct]
kypd: [1×1 struct]
nag: [1×1 struct]
mosek: [1×1 struct]
nomad: []
ooqp: []
penbmi: [1×1 struct]
penlab: []
pensdp: [1×1 struct]
pop: [1×1 struct]
qpoases: []
osqp: []
qsopt: [1×1 struct]
quadprog: [1×1 struct]
quadprogbb: [1×1 struct]
scip: []
scs: [1×1 struct]
sdpa: [1×1 struct]
sdplr: [1×1 struct]
sdpt3: [1×1 struct]
sdpnal: [1×1 struct]
sedumi: [1×1 struct]
sparsepop: [1×1 struct]
sparsecolo: [1×1 struct]
vsdp: [1×1 struct]
xpress: []
Warning: Solver not applicable (mosek)
求解过程中出错
>> optimization;matlab+mosek;optimization MATLAB Answers — New Questions
Is Lisence “Matlab Basic Package” required to use license “Matlab embedded Coder Package”?
Mi question is simple, do I need to have License ""Matlab Basic Package" in order to be able to use "Matlab embedded Coder Package"? or if I only buy "Matlab embedded Coder Package" license is enough for my activities as Model base designer.
Thanks in advanceMi question is simple, do I need to have License ""Matlab Basic Package" in order to be able to use "Matlab embedded Coder Package"? or if I only buy "Matlab embedded Coder Package" license is enough for my activities as Model base designer.
Thanks in advance Mi question is simple, do I need to have License ""Matlab Basic Package" in order to be able to use "Matlab embedded Coder Package"? or if I only buy "Matlab embedded Coder Package" license is enough for my activities as Model base designer.
Thanks in advance license, embedded coder MATLAB Answers — New Questions
Crank-Nicholson method
I am trying too apply Crank-Nicholson method for the following example;
and I have applied the following scheme
I have written the following code but the error is very big and I can’t see where is my mistake
clear all
close all
clc
% Parameters
L = 1; % Length of the rod
T = 1; % Total time
Nx = 10; % Number of spatial grid points
Nt = 50; % Number of time steps
a = 1; % Thermal diffusivity
dx = L / (Nx); % Spatial step size
dt = T / Nt; % Time step size
x = linspace(0, L, Nx); % Spatial grid
t = linspace(0, T, Nt); % Time grid
lx = linspace(0, L, Nx); % Spatial grid
lt = linspace(0, T, Nt);
Exc = @(x,t) x.^2.*exp(t);
[X,T] = meshgrid(lx,lt);
figure(1)
subplot(1,2,1)
surf(X,T,Exc(X,T))
xlabel(‘Space’)
ylabel(‘Time’)
zlabel(‘Temprature’)
title(‘The Exact solution of heat equation ‘)
subplot(1,2,2)
plot(lx,Exc(lx,0),’b’,lx,Exc(lx,0.02),lx,Exc(lx,0.04),lx,Exc(lx,0.06))
grid on
title(‘The Exact at different time level’)
xlabel(‘x’)
ylabel(‘u’)
% Initial condition
u = zeros(Nx,Nt);
% Boundary conditions (assumed zero for simplicity)
u( 1,:) = 0;
u( end,:) = exp(t(:));
%initial condition
u(2:Nx-1,1) = x(2:Nx-1).^2;
% Source term function
f = @(x, t) x.^2-2.*exp(t); % Example source term
% Construct the matrices A and B
Lambda = a * dt / (2 * dx^2);
A = diag((1 + 2*Lambda) * ones(Nx-2, 1)) + diag(-Lambda * ones(Nx-3, 1), 1) + diag(-Lambda * ones(Nx-3, 1), -1);
B = diag((1 – 2*Lambda) * ones(Nx-2, 1)) + diag(Lambda * ones(Nx-3, 1), 1) + diag(Lambda * ones(Nx-3, 1), -1);
% Time-stepping loop
for n = 1:Nt-1
% Source term at time levels n and n+1
f_n = f(x(2:end-1), t(n));
f_np1 = f(x(2:end-1), t(n+1));
% Right-hand side vector
b = B * u(2:end-1,n) + 0.5 * dt * (f_n’ + f_np1′);
% Solve the linear system A * u_new = b
u(2:end-1,n+1)=bA;
%u(2:end-1,n+1) = inv(A)*B*u(2:end-1, n) + 0.5 *dt*inv(A)*(f_n’ + f_np1′);
end
u;
% Visualization
figure(3)
subplot(2,2,1)
surf(x,t,u’)
colormap(‘pink’);
title(‘The approximate solution by Euler forward method for lambda =’,Lambda)
xlabel(‘Space’)
ylabel(‘time’)
zlabel(‘Temperature’)
grid on
subplot(2,2,2)
plot(x,u(:,1),’o’,lx,Exc(lx,0),’b’,x,u(:,round(Nt/4)),’o’,lx,Exc(lx,lt(round(Nt/4))),’–g’,x,u(:,round(Nt/2)),’o’,lx,Exc(lx,lt(round(Nt/2))), x,u(:,round(3*Nt/4)),’o’,lx,Exc(lx,lt(round(3*Nt/4))),’:b’,x,u(:,end),’o’,lx,Exc(lx,lt(end)),’LineWidth’,1)
%plot(x,u(1,:),’o’,lx,Exc(lx,0),’b’,x,u(round(Nt/4),:),’o’,lx,Exc(lx,lt(round(Nt/4))),’–g’,x,u(round(Nt/2),:),’o’,lx,Exc(lx,lt(round(Nt/2))), x,u(round(3*Nt/4),:),’o’,lx,Exc(lx,lt(round(3*Nt/4))),’:b’,x,u(end,:),’o’,lx,Exc(lx,lt(end)),’LineWidth’,1)
title(‘Temperature at different time level’)
xlabel(‘x’)
ylabel(‘T’)
grid on
legend(‘num sol at t=0′,’Exact sol at t=0′,’num sol at t=0.02′,’Exact sol at t=0.02′,’num sol at t=0.04′,’Exact sol at t=0.04′,’num sol at t=0.06′,’Exact sol at t=0.06’)
subplot(2,2,3)
AE=abs(Exc(lx,lt(1))-u(:,1));
AE1=abs(Exc(lx,lt(round(Nt/4)))-u(:,round(Nt/4)));
AE2=abs(Exc(lx,lt(round(Nt/3)))-u(:,round(Nt/3)));
AE3=abs(Exc(lx,lt(round(Nt/2)))-u(:,round(Nt/2)));
AE4=abs(Exc(lx,lt(round(3*Nt/4)))-u(:,round(3*Nt/4)));
AE5=abs(Exc(lx,lt(end))-u(:,end));
lt1=lt(1);
plot(x,AE,’–‘,x,AE1,’o’,x,AE3,’b’,x,AE4,’g’,x,AE5,’LineWidth’,1)
title(‘Absolute error at different time level’)
grid on
legend(‘Error at t=0′,’Error at 1/4 of the time’,’Error at 1/2 of the time’,’Error at 3/4 of the time’,’Error at end of the time’)
subplot(2,2,4)
RE=AE./Exc(lx,lt(1));
RE1=AE1./Exc(lx,lt(round(Nt/4)));
RE2=AE2./Exc(lx,lt(round(Nt/3)));
RE3=AE3./Exc(lx,lt(round(Nt/2)));
RE4=AE4./Exc(lx,lt(round(3*Nt/4)));
RE5=AE5/Exc(lx,lt(end));
plot(x,RE,x,RE1,’–‘,x,RE3,’*’,x,RE4,’b’,x,RE5,’r’,’LineWidth’,1)
legend(‘Error at t=0′,’Error at 1/4 of the time’,’Error at 1/2 of the time’,’Error at 3/4 of the time’,’Error at end of the time’)
grid on
title(‘Relative error at different time level’)I am trying too apply Crank-Nicholson method for the following example;
and I have applied the following scheme
I have written the following code but the error is very big and I can’t see where is my mistake
clear all
close all
clc
% Parameters
L = 1; % Length of the rod
T = 1; % Total time
Nx = 10; % Number of spatial grid points
Nt = 50; % Number of time steps
a = 1; % Thermal diffusivity
dx = L / (Nx); % Spatial step size
dt = T / Nt; % Time step size
x = linspace(0, L, Nx); % Spatial grid
t = linspace(0, T, Nt); % Time grid
lx = linspace(0, L, Nx); % Spatial grid
lt = linspace(0, T, Nt);
Exc = @(x,t) x.^2.*exp(t);
[X,T] = meshgrid(lx,lt);
figure(1)
subplot(1,2,1)
surf(X,T,Exc(X,T))
xlabel(‘Space’)
ylabel(‘Time’)
zlabel(‘Temprature’)
title(‘The Exact solution of heat equation ‘)
subplot(1,2,2)
plot(lx,Exc(lx,0),’b’,lx,Exc(lx,0.02),lx,Exc(lx,0.04),lx,Exc(lx,0.06))
grid on
title(‘The Exact at different time level’)
xlabel(‘x’)
ylabel(‘u’)
% Initial condition
u = zeros(Nx,Nt);
% Boundary conditions (assumed zero for simplicity)
u( 1,:) = 0;
u( end,:) = exp(t(:));
%initial condition
u(2:Nx-1,1) = x(2:Nx-1).^2;
% Source term function
f = @(x, t) x.^2-2.*exp(t); % Example source term
% Construct the matrices A and B
Lambda = a * dt / (2 * dx^2);
A = diag((1 + 2*Lambda) * ones(Nx-2, 1)) + diag(-Lambda * ones(Nx-3, 1), 1) + diag(-Lambda * ones(Nx-3, 1), -1);
B = diag((1 – 2*Lambda) * ones(Nx-2, 1)) + diag(Lambda * ones(Nx-3, 1), 1) + diag(Lambda * ones(Nx-3, 1), -1);
% Time-stepping loop
for n = 1:Nt-1
% Source term at time levels n and n+1
f_n = f(x(2:end-1), t(n));
f_np1 = f(x(2:end-1), t(n+1));
% Right-hand side vector
b = B * u(2:end-1,n) + 0.5 * dt * (f_n’ + f_np1′);
% Solve the linear system A * u_new = b
u(2:end-1,n+1)=bA;
%u(2:end-1,n+1) = inv(A)*B*u(2:end-1, n) + 0.5 *dt*inv(A)*(f_n’ + f_np1′);
end
u;
% Visualization
figure(3)
subplot(2,2,1)
surf(x,t,u’)
colormap(‘pink’);
title(‘The approximate solution by Euler forward method for lambda =’,Lambda)
xlabel(‘Space’)
ylabel(‘time’)
zlabel(‘Temperature’)
grid on
subplot(2,2,2)
plot(x,u(:,1),’o’,lx,Exc(lx,0),’b’,x,u(:,round(Nt/4)),’o’,lx,Exc(lx,lt(round(Nt/4))),’–g’,x,u(:,round(Nt/2)),’o’,lx,Exc(lx,lt(round(Nt/2))), x,u(:,round(3*Nt/4)),’o’,lx,Exc(lx,lt(round(3*Nt/4))),’:b’,x,u(:,end),’o’,lx,Exc(lx,lt(end)),’LineWidth’,1)
%plot(x,u(1,:),’o’,lx,Exc(lx,0),’b’,x,u(round(Nt/4),:),’o’,lx,Exc(lx,lt(round(Nt/4))),’–g’,x,u(round(Nt/2),:),’o’,lx,Exc(lx,lt(round(Nt/2))), x,u(round(3*Nt/4),:),’o’,lx,Exc(lx,lt(round(3*Nt/4))),’:b’,x,u(end,:),’o’,lx,Exc(lx,lt(end)),’LineWidth’,1)
title(‘Temperature at different time level’)
xlabel(‘x’)
ylabel(‘T’)
grid on
legend(‘num sol at t=0′,’Exact sol at t=0′,’num sol at t=0.02′,’Exact sol at t=0.02′,’num sol at t=0.04′,’Exact sol at t=0.04′,’num sol at t=0.06′,’Exact sol at t=0.06’)
subplot(2,2,3)
AE=abs(Exc(lx,lt(1))-u(:,1));
AE1=abs(Exc(lx,lt(round(Nt/4)))-u(:,round(Nt/4)));
AE2=abs(Exc(lx,lt(round(Nt/3)))-u(:,round(Nt/3)));
AE3=abs(Exc(lx,lt(round(Nt/2)))-u(:,round(Nt/2)));
AE4=abs(Exc(lx,lt(round(3*Nt/4)))-u(:,round(3*Nt/4)));
AE5=abs(Exc(lx,lt(end))-u(:,end));
lt1=lt(1);
plot(x,AE,’–‘,x,AE1,’o’,x,AE3,’b’,x,AE4,’g’,x,AE5,’LineWidth’,1)
title(‘Absolute error at different time level’)
grid on
legend(‘Error at t=0′,’Error at 1/4 of the time’,’Error at 1/2 of the time’,’Error at 3/4 of the time’,’Error at end of the time’)
subplot(2,2,4)
RE=AE./Exc(lx,lt(1));
RE1=AE1./Exc(lx,lt(round(Nt/4)));
RE2=AE2./Exc(lx,lt(round(Nt/3)));
RE3=AE3./Exc(lx,lt(round(Nt/2)));
RE4=AE4./Exc(lx,lt(round(3*Nt/4)));
RE5=AE5/Exc(lx,lt(end));
plot(x,RE,x,RE1,’–‘,x,RE3,’*’,x,RE4,’b’,x,RE5,’r’,’LineWidth’,1)
legend(‘Error at t=0′,’Error at 1/4 of the time’,’Error at 1/2 of the time’,’Error at 3/4 of the time’,’Error at end of the time’)
grid on
title(‘Relative error at different time level’) I am trying too apply Crank-Nicholson method for the following example;
and I have applied the following scheme
I have written the following code but the error is very big and I can’t see where is my mistake
clear all
close all
clc
% Parameters
L = 1; % Length of the rod
T = 1; % Total time
Nx = 10; % Number of spatial grid points
Nt = 50; % Number of time steps
a = 1; % Thermal diffusivity
dx = L / (Nx); % Spatial step size
dt = T / Nt; % Time step size
x = linspace(0, L, Nx); % Spatial grid
t = linspace(0, T, Nt); % Time grid
lx = linspace(0, L, Nx); % Spatial grid
lt = linspace(0, T, Nt);
Exc = @(x,t) x.^2.*exp(t);
[X,T] = meshgrid(lx,lt);
figure(1)
subplot(1,2,1)
surf(X,T,Exc(X,T))
xlabel(‘Space’)
ylabel(‘Time’)
zlabel(‘Temprature’)
title(‘The Exact solution of heat equation ‘)
subplot(1,2,2)
plot(lx,Exc(lx,0),’b’,lx,Exc(lx,0.02),lx,Exc(lx,0.04),lx,Exc(lx,0.06))
grid on
title(‘The Exact at different time level’)
xlabel(‘x’)
ylabel(‘u’)
% Initial condition
u = zeros(Nx,Nt);
% Boundary conditions (assumed zero for simplicity)
u( 1,:) = 0;
u( end,:) = exp(t(:));
%initial condition
u(2:Nx-1,1) = x(2:Nx-1).^2;
% Source term function
f = @(x, t) x.^2-2.*exp(t); % Example source term
% Construct the matrices A and B
Lambda = a * dt / (2 * dx^2);
A = diag((1 + 2*Lambda) * ones(Nx-2, 1)) + diag(-Lambda * ones(Nx-3, 1), 1) + diag(-Lambda * ones(Nx-3, 1), -1);
B = diag((1 – 2*Lambda) * ones(Nx-2, 1)) + diag(Lambda * ones(Nx-3, 1), 1) + diag(Lambda * ones(Nx-3, 1), -1);
% Time-stepping loop
for n = 1:Nt-1
% Source term at time levels n and n+1
f_n = f(x(2:end-1), t(n));
f_np1 = f(x(2:end-1), t(n+1));
% Right-hand side vector
b = B * u(2:end-1,n) + 0.5 * dt * (f_n’ + f_np1′);
% Solve the linear system A * u_new = b
u(2:end-1,n+1)=bA;
%u(2:end-1,n+1) = inv(A)*B*u(2:end-1, n) + 0.5 *dt*inv(A)*(f_n’ + f_np1′);
end
u;
% Visualization
figure(3)
subplot(2,2,1)
surf(x,t,u’)
colormap(‘pink’);
title(‘The approximate solution by Euler forward method for lambda =’,Lambda)
xlabel(‘Space’)
ylabel(‘time’)
zlabel(‘Temperature’)
grid on
subplot(2,2,2)
plot(x,u(:,1),’o’,lx,Exc(lx,0),’b’,x,u(:,round(Nt/4)),’o’,lx,Exc(lx,lt(round(Nt/4))),’–g’,x,u(:,round(Nt/2)),’o’,lx,Exc(lx,lt(round(Nt/2))), x,u(:,round(3*Nt/4)),’o’,lx,Exc(lx,lt(round(3*Nt/4))),’:b’,x,u(:,end),’o’,lx,Exc(lx,lt(end)),’LineWidth’,1)
%plot(x,u(1,:),’o’,lx,Exc(lx,0),’b’,x,u(round(Nt/4),:),’o’,lx,Exc(lx,lt(round(Nt/4))),’–g’,x,u(round(Nt/2),:),’o’,lx,Exc(lx,lt(round(Nt/2))), x,u(round(3*Nt/4),:),’o’,lx,Exc(lx,lt(round(3*Nt/4))),’:b’,x,u(end,:),’o’,lx,Exc(lx,lt(end)),’LineWidth’,1)
title(‘Temperature at different time level’)
xlabel(‘x’)
ylabel(‘T’)
grid on
legend(‘num sol at t=0′,’Exact sol at t=0′,’num sol at t=0.02′,’Exact sol at t=0.02′,’num sol at t=0.04′,’Exact sol at t=0.04′,’num sol at t=0.06′,’Exact sol at t=0.06’)
subplot(2,2,3)
AE=abs(Exc(lx,lt(1))-u(:,1));
AE1=abs(Exc(lx,lt(round(Nt/4)))-u(:,round(Nt/4)));
AE2=abs(Exc(lx,lt(round(Nt/3)))-u(:,round(Nt/3)));
AE3=abs(Exc(lx,lt(round(Nt/2)))-u(:,round(Nt/2)));
AE4=abs(Exc(lx,lt(round(3*Nt/4)))-u(:,round(3*Nt/4)));
AE5=abs(Exc(lx,lt(end))-u(:,end));
lt1=lt(1);
plot(x,AE,’–‘,x,AE1,’o’,x,AE3,’b’,x,AE4,’g’,x,AE5,’LineWidth’,1)
title(‘Absolute error at different time level’)
grid on
legend(‘Error at t=0′,’Error at 1/4 of the time’,’Error at 1/2 of the time’,’Error at 3/4 of the time’,’Error at end of the time’)
subplot(2,2,4)
RE=AE./Exc(lx,lt(1));
RE1=AE1./Exc(lx,lt(round(Nt/4)));
RE2=AE2./Exc(lx,lt(round(Nt/3)));
RE3=AE3./Exc(lx,lt(round(Nt/2)));
RE4=AE4./Exc(lx,lt(round(3*Nt/4)));
RE5=AE5/Exc(lx,lt(end));
plot(x,RE,x,RE1,’–‘,x,RE3,’*’,x,RE4,’b’,x,RE5,’r’,’LineWidth’,1)
legend(‘Error at t=0′,’Error at 1/4 of the time’,’Error at 1/2 of the time’,’Error at 3/4 of the time’,’Error at end of the time’)
grid on
title(‘Relative error at different time level’) mathematics, nonlinear, differential equations MATLAB Answers — New Questions
How do I fit a 3rd order polynomial Basis using fitrgp?
Hello,
I am trying to fit a 3rd order polynomial basis using fitgrp for my signal (1×1503). From the instructions, it looks like I would pass hfcn but don’t quite understand how to implement this for the 3rd order polynomial. How would I do this?
Here is code but at the moment it is only implementing a quadratic:
t_observed = (0:length(dodWavelet(:,1))-1)/10;
y_observed = dodWavelet(:,1);
gprMdl1 = fitrgp(t_observed’,y_observed,’Basis’,"pureQuadratic");
[ypred1] = predict(gprMdl1,t_observed’);Hello,
I am trying to fit a 3rd order polynomial basis using fitgrp for my signal (1×1503). From the instructions, it looks like I would pass hfcn but don’t quite understand how to implement this for the 3rd order polynomial. How would I do this?
Here is code but at the moment it is only implementing a quadratic:
t_observed = (0:length(dodWavelet(:,1))-1)/10;
y_observed = dodWavelet(:,1);
gprMdl1 = fitrgp(t_observed’,y_observed,’Basis’,"pureQuadratic");
[ypred1] = predict(gprMdl1,t_observed’); Hello,
I am trying to fit a 3rd order polynomial basis using fitgrp for my signal (1×1503). From the instructions, it looks like I would pass hfcn but don’t quite understand how to implement this for the 3rd order polynomial. How would I do this?
Here is code but at the moment it is only implementing a quadratic:
t_observed = (0:length(dodWavelet(:,1))-1)/10;
y_observed = dodWavelet(:,1);
gprMdl1 = fitrgp(t_observed’,y_observed,’Basis’,"pureQuadratic");
[ypred1] = predict(gprMdl1,t_observed’); functions, curve fitting, fitrgp MATLAB Answers — New Questions
How to find curvature(k) of plane curve have having using it’s position points (x & y) equally spaced with arc length s.
Dear Seniors,
I’m researching on a topic and from many days, i’m so confused, i’m learning to get strong programmming skills, but rightnow i don’t know how to get out of this. I used ”diff” and ”syms” to solve, but it is not effective.
I have a cubic spline curve having arrays of psition x and y equally parsmertize with arclength s. I want to get derivative of x points with respect to s, derivative of y point w.r.t s. and then put in formula to find curvature (k), but i can’t get dy/ds & dx/ds.
points(x&y)=[328.1228 201.8773; 326.2455 203.7545; 324.3683 205.6317; 322.4910 207.5090; 320.6138 209.3826; 318.7365 211.22634; 316.8593 213.1407; 314.9820 215.0180; 313.1048 216.8952; 311.2276 218.7725; 309.3504 220.6489; 307.4731 222.5269; 305.5958 224.4041; 303.7189 226.2818; 301.8424 228.1598]; each position is equally spaced difference of s=2.6548.
for continues acrlength w.r.t position(x&y) along curve i used
acrlen=sqrt((diff(points(:,1))).^2+(diff(points(:,2))).^2);
s=[0 cumsum(arclen’)];Dear Seniors,
I’m researching on a topic and from many days, i’m so confused, i’m learning to get strong programmming skills, but rightnow i don’t know how to get out of this. I used ”diff” and ”syms” to solve, but it is not effective.
I have a cubic spline curve having arrays of psition x and y equally parsmertize with arclength s. I want to get derivative of x points with respect to s, derivative of y point w.r.t s. and then put in formula to find curvature (k), but i can’t get dy/ds & dx/ds.
points(x&y)=[328.1228 201.8773; 326.2455 203.7545; 324.3683 205.6317; 322.4910 207.5090; 320.6138 209.3826; 318.7365 211.22634; 316.8593 213.1407; 314.9820 215.0180; 313.1048 216.8952; 311.2276 218.7725; 309.3504 220.6489; 307.4731 222.5269; 305.5958 224.4041; 303.7189 226.2818; 301.8424 228.1598]; each position is equally spaced difference of s=2.6548.
for continues acrlength w.r.t position(x&y) along curve i used
acrlen=sqrt((diff(points(:,1))).^2+(diff(points(:,2))).^2);
s=[0 cumsum(arclen’)]; Dear Seniors,
I’m researching on a topic and from many days, i’m so confused, i’m learning to get strong programmming skills, but rightnow i don’t know how to get out of this. I used ”diff” and ”syms” to solve, but it is not effective.
I have a cubic spline curve having arrays of psition x and y equally parsmertize with arclength s. I want to get derivative of x points with respect to s, derivative of y point w.r.t s. and then put in formula to find curvature (k), but i can’t get dy/ds & dx/ds.
points(x&y)=[328.1228 201.8773; 326.2455 203.7545; 324.3683 205.6317; 322.4910 207.5090; 320.6138 209.3826; 318.7365 211.22634; 316.8593 213.1407; 314.9820 215.0180; 313.1048 216.8952; 311.2276 218.7725; 309.3504 220.6489; 307.4731 222.5269; 305.5958 224.4041; 303.7189 226.2818; 301.8424 228.1598]; each position is equally spaced difference of s=2.6548.
for continues acrlength w.r.t position(x&y) along curve i used
acrlen=sqrt((diff(points(:,1))).^2+(diff(points(:,2))).^2);
s=[0 cumsum(arclen’)]; partial derivative, curvature (k) MATLAB Answers — New Questions
Why do I receive the error ‘We are unable to validate this email address. Specify a different email address.’?
Why do I receive the error ‘We are unable to validate this email address. Specify a different email address.’ when creating a MathWorks Account or resetting my password?Why do I receive the error ‘We are unable to validate this email address. Specify a different email address.’ when creating a MathWorks Account or resetting my password? Why do I receive the error ‘We are unable to validate this email address. Specify a different email address.’ when creating a MathWorks Account or resetting my password? MATLAB Answers — New Questions
how do i combine two bar graphs
I have tried to combine these two graphics in many ways but nothing works for me, just as the creation of the legends gives me an error. I need help for this because neither the combination nor the legends want to serve me, Thank you!
b1=bar(app.CasosUIAxes,data1.dateRep,data1.cases);
hold on
%grafica de barras 2
b2=bar(app.CasosUIAxes,data2.dateRep,data2.cases);
hold off
legend(app.CasosUIAxes,[b1 b2],’Bar Chart 1′,’Bar Chart 2′)I have tried to combine these two graphics in many ways but nothing works for me, just as the creation of the legends gives me an error. I need help for this because neither the combination nor the legends want to serve me, Thank you!
b1=bar(app.CasosUIAxes,data1.dateRep,data1.cases);
hold on
%grafica de barras 2
b2=bar(app.CasosUIAxes,data2.dateRep,data2.cases);
hold off
legend(app.CasosUIAxes,[b1 b2],’Bar Chart 1′,’Bar Chart 2′) I have tried to combine these two graphics in many ways but nothing works for me, just as the creation of the legends gives me an error. I need help for this because neither the combination nor the legends want to serve me, Thank you!
b1=bar(app.CasosUIAxes,data1.dateRep,data1.cases);
hold on
%grafica de barras 2
b2=bar(app.CasosUIAxes,data2.dateRep,data2.cases);
hold off
legend(app.CasosUIAxes,[b1 b2],’Bar Chart 1′,’Bar Chart 2′) bar-chart matlab mlapp MATLAB Answers — New Questions
Scaling of Filter Coefficients in “fir1” function
Hello Everyone,
I had a quick question.
I was looking through the "fir1" function’s implementation to see how the coeffs are being scaled. I came across this function:
function b = scalefilter(b,First_Band,ff,L)
%SCALEFILTER Scale filter to have passband approx. equal to one.
if First_Band
b = b / sum(b); % unity gain at DC
else
if ff(4)==1
% unity gain at Fs/2
f0 = 1;
else
% unity gain at center of first passband
f0 = mean(ff(3:4));
end
b = b / abs( exp(-1i*2*pi*(0:L-1)*(f0/2))*(b.’) );
end
end
Since there is no documentation for this particular line, I was curious to know where the following equation comes from:
scalingFactor = 1 / abs( exp(-1i*2*pi*(0:L-1)*(f0/2))*(b.’) );
Does anyone know?Hello Everyone,
I had a quick question.
I was looking through the "fir1" function’s implementation to see how the coeffs are being scaled. I came across this function:
function b = scalefilter(b,First_Band,ff,L)
%SCALEFILTER Scale filter to have passband approx. equal to one.
if First_Band
b = b / sum(b); % unity gain at DC
else
if ff(4)==1
% unity gain at Fs/2
f0 = 1;
else
% unity gain at center of first passband
f0 = mean(ff(3:4));
end
b = b / abs( exp(-1i*2*pi*(0:L-1)*(f0/2))*(b.’) );
end
end
Since there is no documentation for this particular line, I was curious to know where the following equation comes from:
scalingFactor = 1 / abs( exp(-1i*2*pi*(0:L-1)*(f0/2))*(b.’) );
Does anyone know? Hello Everyone,
I had a quick question.
I was looking through the "fir1" function’s implementation to see how the coeffs are being scaled. I came across this function:
function b = scalefilter(b,First_Band,ff,L)
%SCALEFILTER Scale filter to have passband approx. equal to one.
if First_Band
b = b / sum(b); % unity gain at DC
else
if ff(4)==1
% unity gain at Fs/2
f0 = 1;
else
% unity gain at center of first passband
f0 = mean(ff(3:4));
end
b = b / abs( exp(-1i*2*pi*(0:L-1)*(f0/2))*(b.’) );
end
end
Since there is no documentation for this particular line, I was curious to know where the following equation comes from:
scalingFactor = 1 / abs( exp(-1i*2*pi*(0:L-1)*(f0/2))*(b.’) );
Does anyone know? digital signal processing, dsp, filter, signal processing, signal MATLAB Answers — New Questions
3D geometry issues with specifyCoefficients (PDE Toolbox)
Hello everyone! I am trying to prepare a heat transfer simulation in an adiabatic pipe. There is a specific formula that I would like my students to compare results with by setting coefficients for the generalized form of the equations solved by PDE Toolbox. Please look at the code below – I would really appreciate your help!
I noticed this error:
Incorrect number or types of inputs or outputs for function specifyCoefficients.
When I checked the documentation, it turns out that my nonconstant coefficients are the correct format, but the model I am specifying is a femodel class as opposed to PDEmodel (requested by the first argument). I made the 3D geometry in house, and I was initially associating it to the model by using femodel(AnalysisType, Geometry), which you can see commented out below.
I then tried to add model_adiabatic.Geometry = g3 hoping that would keep model_adiabatic as a PDEmodel and not a femodel, but it still shows as a femodel when I use class(model) and I am getting another error on top.
I have seen examples with specifyCoefficients used on 3D geometries, but they use importGeometry from external files. I do not have that and I was hoping to keep the code simple and transferable.
Could anybody kindly suggest a fix or anything I have missed?
Thank you!
Michela
% Setting Adiabatic Model
R = 0.05; %m
rho = 1000; %kg/m3
cp = 4182; %J/kgC
model_2 = createpde("thermal","steadystate");
% Geometry
pdecirc(0,0,R);
g = decsg(gd,sf,ns);
g2 = fegeometry(g);
g3 = extrude(g2,1);
model_adiabatic.Geometry = g3
figure;
% model_adiabatic = femodel(AnalysisType="thermalSteady", …
% Geometry=g3);
pdegplot(model_adiabatic,EdgeLabels="on",FaceLabels="on")
title(‘Pipe’)
class(model_adiabatic)
model.MaterialProperties=materialProperties(ThermalConductivity=k,MassDensity=rho, SpecificHeat=cp);
% Boundary Conditions
model_adiabatic.FaceLoad(3) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(4) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(5) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(6) = faceLoad(Heat = 0); % adiabatic wall
T1 = 40;
model_adiabatic.FaceBC(1) = faceBC(Temperature = T1); % entrance temperature, z = 0
% Boundary Conditions
model_adiabatic.FaceLoad(3) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(4) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(5) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(6) = faceLoad(Heat = 0); % adiabatic wall
T1 = 40;
model_adiabatic.FaceBC(1) = faceBC(Temperature = T1); % entrance temperature, z = 0Hello everyone! I am trying to prepare a heat transfer simulation in an adiabatic pipe. There is a specific formula that I would like my students to compare results with by setting coefficients for the generalized form of the equations solved by PDE Toolbox. Please look at the code below – I would really appreciate your help!
I noticed this error:
Incorrect number or types of inputs or outputs for function specifyCoefficients.
When I checked the documentation, it turns out that my nonconstant coefficients are the correct format, but the model I am specifying is a femodel class as opposed to PDEmodel (requested by the first argument). I made the 3D geometry in house, and I was initially associating it to the model by using femodel(AnalysisType, Geometry), which you can see commented out below.
I then tried to add model_adiabatic.Geometry = g3 hoping that would keep model_adiabatic as a PDEmodel and not a femodel, but it still shows as a femodel when I use class(model) and I am getting another error on top.
I have seen examples with specifyCoefficients used on 3D geometries, but they use importGeometry from external files. I do not have that and I was hoping to keep the code simple and transferable.
Could anybody kindly suggest a fix or anything I have missed?
Thank you!
Michela
% Setting Adiabatic Model
R = 0.05; %m
rho = 1000; %kg/m3
cp = 4182; %J/kgC
model_2 = createpde("thermal","steadystate");
% Geometry
pdecirc(0,0,R);
g = decsg(gd,sf,ns);
g2 = fegeometry(g);
g3 = extrude(g2,1);
model_adiabatic.Geometry = g3
figure;
% model_adiabatic = femodel(AnalysisType="thermalSteady", …
% Geometry=g3);
pdegplot(model_adiabatic,EdgeLabels="on",FaceLabels="on")
title(‘Pipe’)
class(model_adiabatic)
model.MaterialProperties=materialProperties(ThermalConductivity=k,MassDensity=rho, SpecificHeat=cp);
% Boundary Conditions
model_adiabatic.FaceLoad(3) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(4) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(5) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(6) = faceLoad(Heat = 0); % adiabatic wall
T1 = 40;
model_adiabatic.FaceBC(1) = faceBC(Temperature = T1); % entrance temperature, z = 0
% Boundary Conditions
model_adiabatic.FaceLoad(3) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(4) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(5) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(6) = faceLoad(Heat = 0); % adiabatic wall
T1 = 40;
model_adiabatic.FaceBC(1) = faceBC(Temperature = T1); % entrance temperature, z = 0 Hello everyone! I am trying to prepare a heat transfer simulation in an adiabatic pipe. There is a specific formula that I would like my students to compare results with by setting coefficients for the generalized form of the equations solved by PDE Toolbox. Please look at the code below – I would really appreciate your help!
I noticed this error:
Incorrect number or types of inputs or outputs for function specifyCoefficients.
When I checked the documentation, it turns out that my nonconstant coefficients are the correct format, but the model I am specifying is a femodel class as opposed to PDEmodel (requested by the first argument). I made the 3D geometry in house, and I was initially associating it to the model by using femodel(AnalysisType, Geometry), which you can see commented out below.
I then tried to add model_adiabatic.Geometry = g3 hoping that would keep model_adiabatic as a PDEmodel and not a femodel, but it still shows as a femodel when I use class(model) and I am getting another error on top.
I have seen examples with specifyCoefficients used on 3D geometries, but they use importGeometry from external files. I do not have that and I was hoping to keep the code simple and transferable.
Could anybody kindly suggest a fix or anything I have missed?
Thank you!
Michela
% Setting Adiabatic Model
R = 0.05; %m
rho = 1000; %kg/m3
cp = 4182; %J/kgC
model_2 = createpde("thermal","steadystate");
% Geometry
pdecirc(0,0,R);
g = decsg(gd,sf,ns);
g2 = fegeometry(g);
g3 = extrude(g2,1);
model_adiabatic.Geometry = g3
figure;
% model_adiabatic = femodel(AnalysisType="thermalSteady", …
% Geometry=g3);
pdegplot(model_adiabatic,EdgeLabels="on",FaceLabels="on")
title(‘Pipe’)
class(model_adiabatic)
model.MaterialProperties=materialProperties(ThermalConductivity=k,MassDensity=rho, SpecificHeat=cp);
% Boundary Conditions
model_adiabatic.FaceLoad(3) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(4) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(5) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(6) = faceLoad(Heat = 0); % adiabatic wall
T1 = 40;
model_adiabatic.FaceBC(1) = faceBC(Temperature = T1); % entrance temperature, z = 0
% Boundary Conditions
model_adiabatic.FaceLoad(3) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(4) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(5) = faceLoad(Heat = 0); % adiabatic wall
model_adiabatic.FaceLoad(6) = faceLoad(Heat = 0); % adiabatic wall
T1 = 40;
model_adiabatic.FaceBC(1) = faceBC(Temperature = T1); % entrance temperature, z = 0 pde toolbox MATLAB Answers — New Questions
I am getting Negative speed in PMSM FOC using MTPA controller block.
I am trying to implement Field oriented control under field weakening condition for PMSM motor. Manually setting value of Id to negative values, I am getting desired results of speed and Torque but when i try to use MTPA Controller block, speed always get negative to certain RPM and then saturates (see image below). I have attached images of parameters used in MTPA and Motor block, please help me in following what I am doing wrong and how to resolve it. P=0.05 and I = 4 for all PI controllers here i used.
Block Diagram:
Block Parameters:
Result:I am trying to implement Field oriented control under field weakening condition for PMSM motor. Manually setting value of Id to negative values, I am getting desired results of speed and Torque but when i try to use MTPA Controller block, speed always get negative to certain RPM and then saturates (see image below). I have attached images of parameters used in MTPA and Motor block, please help me in following what I am doing wrong and how to resolve it. P=0.05 and I = 4 for all PI controllers here i used.
Block Diagram:
Block Parameters:
Result: I am trying to implement Field oriented control under field weakening condition for PMSM motor. Manually setting value of Id to negative values, I am getting desired results of speed and Torque but when i try to use MTPA Controller block, speed always get negative to certain RPM and then saturates (see image below). I have attached images of parameters used in MTPA and Motor block, please help me in following what I am doing wrong and how to resolve it. P=0.05 and I = 4 for all PI controllers here i used.
Block Diagram:
Block Parameters:
Result: electric_motor_control, pmsm, foc, mtpa, field_weakening_control, field_oriented_control MATLAB Answers — New Questions
Multiple outputs using Legacy Toolbox
Hi, i’m currently working on a project and I have to create a s-function written in C language. I have multiple outputs (V, m, h & fm) and multiple inputs(q1, q2, qe & qo). Here’s my main file:
#include "Reservoir.h"
#include <math.h>
double Reservoir(double q1,
double q2,
double qe,
double qo,
double *V,
double *m,
double *h,
double *fm)
{
*V = q1 + q2 + qe – qo;
*m = 1875.0 * q1 + 1667.0 * q2 + 1000.0 * qe – 1468.48 * qo;
*h = sqrt(*V + 1) – 1;
*fm = ((3000.0) * (1 – 1000.0)) / ((3000.0 – 1000.0) * (*m/*V))
}
And here’s my header file :
#ifndef RESERVOIR_H_INCLUDED
#define RESERVOIR_H_INCLUDED
double Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm);
#endif // RESERVOIR_H_INCLUDED
I’M also working with Legacy Toolbox to generate a tlc file and the s-function. I’m using these lines to generate the s-function :
def = legacy_code(‘initialize’)
def.SFunctionName = ‘S_function1’
def.OutputFcnSpec = ‘Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)’
def.HeaderFiles = {‘Reservoir.h’}
def.SourceFiles = {‘main.c’}
legacy_code(‘sfcn_cmex_generate’, def)
When i execute the last line, i receive this error :
Error using legacycode.LCT.legacyCodeImpl
Unrecognized elements in the function specification:
–> Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)
Error in legacy_code (line 103)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
Thus, I was wondering what i’ve done wrong ? Thanks for your help.Hi, i’m currently working on a project and I have to create a s-function written in C language. I have multiple outputs (V, m, h & fm) and multiple inputs(q1, q2, qe & qo). Here’s my main file:
#include "Reservoir.h"
#include <math.h>
double Reservoir(double q1,
double q2,
double qe,
double qo,
double *V,
double *m,
double *h,
double *fm)
{
*V = q1 + q2 + qe – qo;
*m = 1875.0 * q1 + 1667.0 * q2 + 1000.0 * qe – 1468.48 * qo;
*h = sqrt(*V + 1) – 1;
*fm = ((3000.0) * (1 – 1000.0)) / ((3000.0 – 1000.0) * (*m/*V))
}
And here’s my header file :
#ifndef RESERVOIR_H_INCLUDED
#define RESERVOIR_H_INCLUDED
double Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm);
#endif // RESERVOIR_H_INCLUDED
I’M also working with Legacy Toolbox to generate a tlc file and the s-function. I’m using these lines to generate the s-function :
def = legacy_code(‘initialize’)
def.SFunctionName = ‘S_function1’
def.OutputFcnSpec = ‘Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)’
def.HeaderFiles = {‘Reservoir.h’}
def.SourceFiles = {‘main.c’}
legacy_code(‘sfcn_cmex_generate’, def)
When i execute the last line, i receive this error :
Error using legacycode.LCT.legacyCodeImpl
Unrecognized elements in the function specification:
–> Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)
Error in legacy_code (line 103)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
Thus, I was wondering what i’ve done wrong ? Thanks for your help. Hi, i’m currently working on a project and I have to create a s-function written in C language. I have multiple outputs (V, m, h & fm) and multiple inputs(q1, q2, qe & qo). Here’s my main file:
#include "Reservoir.h"
#include <math.h>
double Reservoir(double q1,
double q2,
double qe,
double qo,
double *V,
double *m,
double *h,
double *fm)
{
*V = q1 + q2 + qe – qo;
*m = 1875.0 * q1 + 1667.0 * q2 + 1000.0 * qe – 1468.48 * qo;
*h = sqrt(*V + 1) – 1;
*fm = ((3000.0) * (1 – 1000.0)) / ((3000.0 – 1000.0) * (*m/*V))
}
And here’s my header file :
#ifndef RESERVOIR_H_INCLUDED
#define RESERVOIR_H_INCLUDED
double Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm);
#endif // RESERVOIR_H_INCLUDED
I’M also working with Legacy Toolbox to generate a tlc file and the s-function. I’m using these lines to generate the s-function :
def = legacy_code(‘initialize’)
def.SFunctionName = ‘S_function1’
def.OutputFcnSpec = ‘Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)’
def.HeaderFiles = {‘Reservoir.h’}
def.SourceFiles = {‘main.c’}
legacy_code(‘sfcn_cmex_generate’, def)
When i execute the last line, i receive this error :
Error using legacycode.LCT.legacyCodeImpl
Unrecognized elements in the function specification:
–> Reservoir(double q1, double q2, double qe, double qo, double *V, double *m, double *h, double *fm)
Error in legacy_code (line 103)
[varargout{1:nargout}] = legacycode.LCT.legacyCodeImpl(action, varargin{1:end});
Thus, I was wondering what i’ve done wrong ? Thanks for your help. legacy, code, c language MATLAB Answers — New Questions
Committing using ‘Commit’ button in Project tab is so slow
Hi all,
Say I am working on a project-enabled git repo which gives me the Project tab whenever I open my *.prj file. Everything works fine and all, until when it’s time for me to commit my changes. Let’s say I wanna commit all changes, so logically I would use the ‘Commit’ button in the Project tab:
Eventhough it is just small changes, it takes almost a minute to for the committing to complete! This is shown by this rotating circle progress indicator ‘Checking in files’:
In contrast, if I were to commit the files individually using the right-click context menu like this:
It takes less than a second! Why is this, and if this is a bug, please fix it since committing using the button is convenient to commit all changes at once.
Thank you!Hi all,
Say I am working on a project-enabled git repo which gives me the Project tab whenever I open my *.prj file. Everything works fine and all, until when it’s time for me to commit my changes. Let’s say I wanna commit all changes, so logically I would use the ‘Commit’ button in the Project tab:
Eventhough it is just small changes, it takes almost a minute to for the committing to complete! This is shown by this rotating circle progress indicator ‘Checking in files’:
In contrast, if I were to commit the files individually using the right-click context menu like this:
It takes less than a second! Why is this, and if this is a bug, please fix it since committing using the button is convenient to commit all changes at once.
Thank you! Hi all,
Say I am working on a project-enabled git repo which gives me the Project tab whenever I open my *.prj file. Everything works fine and all, until when it’s time for me to commit my changes. Let’s say I wanna commit all changes, so logically I would use the ‘Commit’ button in the Project tab:
Eventhough it is just small changes, it takes almost a minute to for the committing to complete! This is shown by this rotating circle progress indicator ‘Checking in files’:
In contrast, if I were to commit the files individually using the right-click context menu like this:
It takes less than a second! Why is this, and if this is a bug, please fix it since committing using the button is convenient to commit all changes at once.
Thank you! matlab, project, git, commit MATLAB Answers — New Questions
Matlab Code for Performance Analysis (BER vs Eb_N0) of BPSK, QPSK & 16QAM, on 4G LTE
Please can someone kindly help to edit this code i got from Nischay Malhan (youtube account) to fit in for BER performance evaluation of bpsk, qpsk and 16qam on 4G LTE. Thank you you assist.
The code below:
clc;
close all;
EbN0dB=-4:1:24;
EbN0lin=10.^(EbN0dB/10);
colors={‘k-*’,’g-o’,’r-h’,’c-s’,’m-s’,’y-*’,’k-p’,’b:s’,’m:d’,’g:p’};
index=1;
%BPSK
BPSK = 0.5*erfc(sqrt(EbN0lin));
plotHandle=plot(EbN0dB,log10(BPSK),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
hold on;
index=index+1;
%M-PSK
m=2:1:5;
M=2.^m;
for i=M,
k=log2(i);
berErr = 1/k*erfc(sqrt(EbN0lin*k)*sin(pi/i));
plotHandle=plot(EbN0dB,log10(berErr),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
end
%Binary DPSK
Pb = 0.5*exp(-EbN0lin);
plotHandle = plot(EbN0dB,log10(Pb),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
%Differential QPSK
a=sqrt(2*EbN0lin*(1-sqrt(1/2)));
b=sqrt(2*EbN0lin*(1+sqrt(1/2)));
Pb = marcumq(a,b)-1/2.*besseli(0,a.*b).*exp(-1/2*(a.^2+b.^2));
plotHandle = plot(EbN0dB,log10(Pb),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
%M-QAM
m=2:2:6;
M=2.^m;
for i=M,
k=log2(i);
berErr = 2/k*(1-1/sqrt(i))*erfc(sqrt(3*EbN0lin*k/(2*(i-1))));
plotHandle=plot(EbN0dB,log10(berErr),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
end
legend(‘BPSK’,’QPSK’,’8-PSK’,’16-PSK’,’32-PSK’,’D-BPSK’,’D-QPSK’,’4-QAM’,’16-QAM’,’64-QAM’);
axis([-4 24 -8 0]);
set(gca,’XTick’,-4:1:24);
ylabel(‘Probability of BER Error – log10(Pb)’);
xlabel(‘Eb/N0 (dB)’);
title(‘Probability of BER Error log10(Pb) Vs Eb/N0’);
grid on;Please can someone kindly help to edit this code i got from Nischay Malhan (youtube account) to fit in for BER performance evaluation of bpsk, qpsk and 16qam on 4G LTE. Thank you you assist.
The code below:
clc;
close all;
EbN0dB=-4:1:24;
EbN0lin=10.^(EbN0dB/10);
colors={‘k-*’,’g-o’,’r-h’,’c-s’,’m-s’,’y-*’,’k-p’,’b:s’,’m:d’,’g:p’};
index=1;
%BPSK
BPSK = 0.5*erfc(sqrt(EbN0lin));
plotHandle=plot(EbN0dB,log10(BPSK),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
hold on;
index=index+1;
%M-PSK
m=2:1:5;
M=2.^m;
for i=M,
k=log2(i);
berErr = 1/k*erfc(sqrt(EbN0lin*k)*sin(pi/i));
plotHandle=plot(EbN0dB,log10(berErr),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
end
%Binary DPSK
Pb = 0.5*exp(-EbN0lin);
plotHandle = plot(EbN0dB,log10(Pb),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
%Differential QPSK
a=sqrt(2*EbN0lin*(1-sqrt(1/2)));
b=sqrt(2*EbN0lin*(1+sqrt(1/2)));
Pb = marcumq(a,b)-1/2.*besseli(0,a.*b).*exp(-1/2*(a.^2+b.^2));
plotHandle = plot(EbN0dB,log10(Pb),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
%M-QAM
m=2:2:6;
M=2.^m;
for i=M,
k=log2(i);
berErr = 2/k*(1-1/sqrt(i))*erfc(sqrt(3*EbN0lin*k/(2*(i-1))));
plotHandle=plot(EbN0dB,log10(berErr),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
end
legend(‘BPSK’,’QPSK’,’8-PSK’,’16-PSK’,’32-PSK’,’D-BPSK’,’D-QPSK’,’4-QAM’,’16-QAM’,’64-QAM’);
axis([-4 24 -8 0]);
set(gca,’XTick’,-4:1:24);
ylabel(‘Probability of BER Error – log10(Pb)’);
xlabel(‘Eb/N0 (dB)’);
title(‘Probability of BER Error log10(Pb) Vs Eb/N0’);
grid on; Please can someone kindly help to edit this code i got from Nischay Malhan (youtube account) to fit in for BER performance evaluation of bpsk, qpsk and 16qam on 4G LTE. Thank you you assist.
The code below:
clc;
close all;
EbN0dB=-4:1:24;
EbN0lin=10.^(EbN0dB/10);
colors={‘k-*’,’g-o’,’r-h’,’c-s’,’m-s’,’y-*’,’k-p’,’b:s’,’m:d’,’g:p’};
index=1;
%BPSK
BPSK = 0.5*erfc(sqrt(EbN0lin));
plotHandle=plot(EbN0dB,log10(BPSK),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
hold on;
index=index+1;
%M-PSK
m=2:1:5;
M=2.^m;
for i=M,
k=log2(i);
berErr = 1/k*erfc(sqrt(EbN0lin*k)*sin(pi/i));
plotHandle=plot(EbN0dB,log10(berErr),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
end
%Binary DPSK
Pb = 0.5*exp(-EbN0lin);
plotHandle = plot(EbN0dB,log10(Pb),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
%Differential QPSK
a=sqrt(2*EbN0lin*(1-sqrt(1/2)));
b=sqrt(2*EbN0lin*(1+sqrt(1/2)));
Pb = marcumq(a,b)-1/2.*besseli(0,a.*b).*exp(-1/2*(a.^2+b.^2));
plotHandle = plot(EbN0dB,log10(Pb),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
%M-QAM
m=2:2:6;
M=2.^m;
for i=M,
k=log2(i);
berErr = 2/k*(1-1/sqrt(i))*erfc(sqrt(3*EbN0lin*k/(2*(i-1))));
plotHandle=plot(EbN0dB,log10(berErr),char(colors(index)));
set(plotHandle,’LineWidth’,1.5);
index=index+1;
end
legend(‘BPSK’,’QPSK’,’8-PSK’,’16-PSK’,’32-PSK’,’D-BPSK’,’D-QPSK’,’4-QAM’,’16-QAM’,’64-QAM’);
axis([-4 24 -8 0]);
set(gca,’XTick’,-4:1:24);
ylabel(‘Probability of BER Error – log10(Pb)’);
xlabel(‘Eb/N0 (dB)’);
title(‘Probability of BER Error log10(Pb) Vs Eb/N0’);
grid on; matlab code for performance analysis (ber vs eb_n0) if digital modulation schemes. MATLAB Answers — New Questions