Category: Matlab
Category Archives: Matlab
How can i solve this eqaution in matlab?
How can i solve this eqaution in matlab?
where the X is the propellant length = 0 to 4.5 meters
clc; clear;
global Go A Rho_f P n m a Reg_dot_dt_values Reg_dot_dt_values2
Rho_f = 920; %kg/m^3
Dp = 0.152; % m
m_dot_oxi = 7.95; %kg/s
n = 0.75;
m = -0.15;
a = 2.006e-5;
Rp = Dp/2; % m
A = pi*(Rp^2); % Port area
Go = m_dot_oxi/A; % Oxidizer mass flux
P = 2*pi*Rp; % Perimeter
Reg_dot_dt_values = [];
[x,R] = ode45(@f, [0 10], 0.076);
function Reg_dot_dt = f(x,R)
global Go A Rho_f P n m a Reg_dot_dt_values Reg_dot_dt_values2
Reg_dot_dt = (a*(Go^n)*(x^m))*((1+(((1-n)*Rho_f*P*a*(x^(1+m)))/((1+m)*A*(Go^(1-n)))))^(n/1-n));
Reg_dot_dt2 = a*(Go^n).*(((1+(Rho_f*P/Go*A).*Reg_dot_dt)^(n)).*(x^m));
Reg_dot_dt_values = [Reg_dot_dt_values; Reg_dot_dt];
endHow can i solve this eqaution in matlab?
where the X is the propellant length = 0 to 4.5 meters
clc; clear;
global Go A Rho_f P n m a Reg_dot_dt_values Reg_dot_dt_values2
Rho_f = 920; %kg/m^3
Dp = 0.152; % m
m_dot_oxi = 7.95; %kg/s
n = 0.75;
m = -0.15;
a = 2.006e-5;
Rp = Dp/2; % m
A = pi*(Rp^2); % Port area
Go = m_dot_oxi/A; % Oxidizer mass flux
P = 2*pi*Rp; % Perimeter
Reg_dot_dt_values = [];
[x,R] = ode45(@f, [0 10], 0.076);
function Reg_dot_dt = f(x,R)
global Go A Rho_f P n m a Reg_dot_dt_values Reg_dot_dt_values2
Reg_dot_dt = (a*(Go^n)*(x^m))*((1+(((1-n)*Rho_f*P*a*(x^(1+m)))/((1+m)*A*(Go^(1-n)))))^(n/1-n));
Reg_dot_dt2 = a*(Go^n).*(((1+(Rho_f*P/Go*A).*Reg_dot_dt)^(n)).*(x^m));
Reg_dot_dt_values = [Reg_dot_dt_values; Reg_dot_dt];
end How can i solve this eqaution in matlab?
where the X is the propellant length = 0 to 4.5 meters
clc; clear;
global Go A Rho_f P n m a Reg_dot_dt_values Reg_dot_dt_values2
Rho_f = 920; %kg/m^3
Dp = 0.152; % m
m_dot_oxi = 7.95; %kg/s
n = 0.75;
m = -0.15;
a = 2.006e-5;
Rp = Dp/2; % m
A = pi*(Rp^2); % Port area
Go = m_dot_oxi/A; % Oxidizer mass flux
P = 2*pi*Rp; % Perimeter
Reg_dot_dt_values = [];
[x,R] = ode45(@f, [0 10], 0.076);
function Reg_dot_dt = f(x,R)
global Go A Rho_f P n m a Reg_dot_dt_values Reg_dot_dt_values2
Reg_dot_dt = (a*(Go^n)*(x^m))*((1+(((1-n)*Rho_f*P*a*(x^(1+m)))/((1+m)*A*(Go^(1-n)))))^(n/1-n));
Reg_dot_dt2 = a*(Go^n).*(((1+(Rho_f*P/Go*A).*Reg_dot_dt)^(n)).*(x^m));
Reg_dot_dt_values = [Reg_dot_dt_values; Reg_dot_dt];
end ode MATLAB Answers — New Questions
How To Purchase Add-Ons for an Existing Home/Student License:
I have purchased a Home/Student Version license and would like to add additional toolboxes to my license.
How can I purchase additional toolboxes for use with Home/Student Version of MATLAB?I have purchased a Home/Student Version license and would like to add additional toolboxes to my license.
How can I purchase additional toolboxes for use with Home/Student Version of MATLAB? I have purchased a Home/Student Version license and would like to add additional toolboxes to my license.
How can I purchase additional toolboxes for use with Home/Student Version of MATLAB? add, on, purchase, student, version, toolboxes, additional, tools MATLAB Answers — New Questions
Why is it running as a Triangulation
I am running the exact same script as my coworker is, same version of matlab, same package of stlTools, everything is the same except for the laptops, though the same type of laptop, two sepearate devices. Yet, when he runs the script is runs as a double which then allows him to run it with no errors, whereas when I run the script it runs as a triangulation with different values resulting in the error on the screen. We can’t figure out why mine keeps runnign as a triangulation and failing whilst his is running perfectly fine, any ideas?I am running the exact same script as my coworker is, same version of matlab, same package of stlTools, everything is the same except for the laptops, though the same type of laptop, two sepearate devices. Yet, when he runs the script is runs as a double which then allows him to run it with no errors, whereas when I run the script it runs as a triangulation with different values resulting in the error on the screen. We can’t figure out why mine keeps runnign as a triangulation and failing whilst his is running perfectly fine, any ideas? I am running the exact same script as my coworker is, same version of matlab, same package of stlTools, everything is the same except for the laptops, though the same type of laptop, two sepearate devices. Yet, when he runs the script is runs as a double which then allows him to run it with no errors, whereas when I run the script it runs as a triangulation with different values resulting in the error on the screen. We can’t figure out why mine keeps runnign as a triangulation and failing whilst his is running perfectly fine, any ideas? triangulation struct MATLAB Answers — New Questions
Plotting multiple lines with a for loop: only last plot shows
Hello everyone!
I am trying to plot my results following Temperatures for a Transient Thermal Model on a Square on https://www.mathworks.com/help/pde/ug/pde.steadystatethermalresults.interpolatetemperature.html. However, the only plot that shows is the one at the end of the t array (t = 952), plus an unlabelled one: could anybody please help me understand what I am doing differently?
X = cell2mat(num2cell(linspace(-3,3,1001)))
class(X)
Y = cell2mat(num2cell(ones(size(X))));
class(Y)
Tintrp = interpolateTemperature(results,X,Y,1:length(tlist))
class(Tintrp)
tf = isvector(Tintrp)
tf = ismatrix(Tintrp)
tf = isnumeric(Tintrp)
Xs = (linspace(-3,3,1001))
Xs = reshape(Xs,[],1)
tf = isvector(Xs)
tf = isnumeric(Xs)
figure
xlabel("x")
ylabel("Tintrp")
t = [2:50:1001]
% for i = t
% Tintrp(:,i)
% tf = isnumeric(Tintrp(:,i))
% p(i) = plot(Xs,Tintrp(:,i),"DisplayName", …
% strcat("t=",num2str(tlist(i))));
% hold on
% end
for i = t
p(i) = plot(Xs,Tintrp(:,i),"DisplayName", …
strcat("t=",num2str(tlist(i))));
legend(p(i))
hold on
end
legendHello everyone!
I am trying to plot my results following Temperatures for a Transient Thermal Model on a Square on https://www.mathworks.com/help/pde/ug/pde.steadystatethermalresults.interpolatetemperature.html. However, the only plot that shows is the one at the end of the t array (t = 952), plus an unlabelled one: could anybody please help me understand what I am doing differently?
X = cell2mat(num2cell(linspace(-3,3,1001)))
class(X)
Y = cell2mat(num2cell(ones(size(X))));
class(Y)
Tintrp = interpolateTemperature(results,X,Y,1:length(tlist))
class(Tintrp)
tf = isvector(Tintrp)
tf = ismatrix(Tintrp)
tf = isnumeric(Tintrp)
Xs = (linspace(-3,3,1001))
Xs = reshape(Xs,[],1)
tf = isvector(Xs)
tf = isnumeric(Xs)
figure
xlabel("x")
ylabel("Tintrp")
t = [2:50:1001]
% for i = t
% Tintrp(:,i)
% tf = isnumeric(Tintrp(:,i))
% p(i) = plot(Xs,Tintrp(:,i),"DisplayName", …
% strcat("t=",num2str(tlist(i))));
% hold on
% end
for i = t
p(i) = plot(Xs,Tintrp(:,i),"DisplayName", …
strcat("t=",num2str(tlist(i))));
legend(p(i))
hold on
end
legend Hello everyone!
I am trying to plot my results following Temperatures for a Transient Thermal Model on a Square on https://www.mathworks.com/help/pde/ug/pde.steadystatethermalresults.interpolatetemperature.html. However, the only plot that shows is the one at the end of the t array (t = 952), plus an unlabelled one: could anybody please help me understand what I am doing differently?
X = cell2mat(num2cell(linspace(-3,3,1001)))
class(X)
Y = cell2mat(num2cell(ones(size(X))));
class(Y)
Tintrp = interpolateTemperature(results,X,Y,1:length(tlist))
class(Tintrp)
tf = isvector(Tintrp)
tf = ismatrix(Tintrp)
tf = isnumeric(Tintrp)
Xs = (linspace(-3,3,1001))
Xs = reshape(Xs,[],1)
tf = isvector(Xs)
tf = isnumeric(Xs)
figure
xlabel("x")
ylabel("Tintrp")
t = [2:50:1001]
% for i = t
% Tintrp(:,i)
% tf = isnumeric(Tintrp(:,i))
% p(i) = plot(Xs,Tintrp(:,i),"DisplayName", …
% strcat("t=",num2str(tlist(i))));
% hold on
% end
for i = t
p(i) = plot(Xs,Tintrp(:,i),"DisplayName", …
strcat("t=",num2str(tlist(i))));
legend(p(i))
hold on
end
legend plotting, pde, for loop MATLAB Answers — New Questions
How to make assembly between induction motor,centrifugal pump and open/close valve for tank in simulink. Please guide to work out my query
I want to measure the level of water tank,as the level goes below set point (25)valve should be opened and as it is above setpoint(75)then valve should be closed,so that water which is pumped from another tank cannot enter or viceversa.
I have difficulty in selecting valve assembly and level indicatorI want to measure the level of water tank,as the level goes below set point (25)valve should be opened and as it is above setpoint(75)then valve should be closed,so that water which is pumped from another tank cannot enter or viceversa.
I have difficulty in selecting valve assembly and level indicator I want to measure the level of water tank,as the level goes below set point (25)valve should be opened and as it is above setpoint(75)then valve should be closed,so that water which is pumped from another tank cannot enter or viceversa.
I have difficulty in selecting valve assembly and level indicator water tank model, power_electronics_control, electric_motor_control MATLAB Answers — New Questions
Issue with solving ill-conditioned DAE system on MATLAB 2023b
Kindly I want to know if there any changes in some solvers like ODE113?
Recently I have updated matlab to 2023b version and tried to run a script that I have excuted it before with nothing changed on older version of matlab, the script contains solving DAE system Ax = B, with ill-conditioned A matrix, using ODE113 of an older version it was working with conditiong number was around e-21. my results using older version was compared to some other CAEs (figure below) and they were identical, so I do not know what is the issue in 2023b, any help please?Kindly I want to know if there any changes in some solvers like ODE113?
Recently I have updated matlab to 2023b version and tried to run a script that I have excuted it before with nothing changed on older version of matlab, the script contains solving DAE system Ax = B, with ill-conditioned A matrix, using ODE113 of an older version it was working with conditiong number was around e-21. my results using older version was compared to some other CAEs (figure below) and they were identical, so I do not know what is the issue in 2023b, any help please? Kindly I want to know if there any changes in some solvers like ODE113?
Recently I have updated matlab to 2023b version and tried to run a script that I have excuted it before with nothing changed on older version of matlab, the script contains solving DAE system Ax = B, with ill-conditioned A matrix, using ODE113 of an older version it was working with conditiong number was around e-21. my results using older version was compared to some other CAEs (figure below) and they were identical, so I do not know what is the issue in 2023b, any help please? ode, dae, matlab 2023b MATLAB Answers — New Questions
How to remove decimal points in the Workspace
I want to remove decimal points in the workspace, I have a bunch of variables in the editor and want to be able to quickly reference the output in the work space but when i do they are in scientific notation. Ive tried changing the veiw but nothing works. Ill show an example below but some other things that I have tried is rounding, format longG and others, but nothing removes the decimal all together.
I have an excel sheet with alot of different variables, in numerous columns, I want to add all the values together to have just one total. Afterward Ill graph all of the different totals.
Heres how I am doing it now:
a1 =
339.750000000000
339.750000000000
339.750000000000
339.750000000000
339.750000000000
a2 = sum(a1);
output for a1 = 1.698750+03
a3 = round(a2,2);
after rounding, a3 = 1.698750+03
what I am looking for = 1698.75
When I open the variable in workspace I want it to look like the final number, 1698.75, instead of 1.698750+03. Any advice is appreciated!I want to remove decimal points in the workspace, I have a bunch of variables in the editor and want to be able to quickly reference the output in the work space but when i do they are in scientific notation. Ive tried changing the veiw but nothing works. Ill show an example below but some other things that I have tried is rounding, format longG and others, but nothing removes the decimal all together.
I have an excel sheet with alot of different variables, in numerous columns, I want to add all the values together to have just one total. Afterward Ill graph all of the different totals.
Heres how I am doing it now:
a1 =
339.750000000000
339.750000000000
339.750000000000
339.750000000000
339.750000000000
a2 = sum(a1);
output for a1 = 1.698750+03
a3 = round(a2,2);
after rounding, a3 = 1.698750+03
what I am looking for = 1698.75
When I open the variable in workspace I want it to look like the final number, 1698.75, instead of 1.698750+03. Any advice is appreciated! I want to remove decimal points in the workspace, I have a bunch of variables in the editor and want to be able to quickly reference the output in the work space but when i do they are in scientific notation. Ive tried changing the veiw but nothing works. Ill show an example below but some other things that I have tried is rounding, format longG and others, but nothing removes the decimal all together.
I have an excel sheet with alot of different variables, in numerous columns, I want to add all the values together to have just one total. Afterward Ill graph all of the different totals.
Heres how I am doing it now:
a1 =
339.750000000000
339.750000000000
339.750000000000
339.750000000000
339.750000000000
a2 = sum(a1);
output for a1 = 1.698750+03
a3 = round(a2,2);
after rounding, a3 = 1.698750+03
what I am looking for = 1698.75
When I open the variable in workspace I want it to look like the final number, 1698.75, instead of 1.698750+03. Any advice is appreciated! round MATLAB Answers — New Questions
UAVPathManagerBus issue in the 3D Obstacle Avoidance UAV Package delivery
Hi,
I’m trying to modify the UAV Package Delivery project such as it allows multiple waypoints while avoiding obstacles, using QGroundConrol. Until now I have done these:
-modified replaced FollowWaypoints with the guidance from FullGuidanceLogic
However, MissionData input must be bus signal "uavPathManagerBus"
Currently, the MissionData comes from the function that contains the OA algorithm:
function [y, DTD, needHover] = computeLPWaypoints(mission, Steer,UAVState)
%#codegen
Wp1 = [mission(1).position’ mission(1).params(4)];
Wp2x = mission(2).position(1);
Wp2y = mission(2).position(2);
needHover = false;
% Follow obstacle avoidance steer direction when UAV is above 5 meters
% above ground
if (~any(isnan(Steer)) && (UAVState.z < -5))
if (Steer(5) == 0)
% Compute look ahead point 6 meters along the steering direction
LAP_local = 6*Steer(2:4)’;
% Follow yaw command from obstacle avoidance
yaw = Steer(1);
LAP = [LAP_local yaw] + [UAVState.x, UAVState.y, UAVState.z, 0];
if(isnan(LAP(4)))
LAP(4) = 0;
end
y = [ Wp1(1,:) ; LAP ; Wp2x , Wp2y , 0 , LAP(4) ];
DTD = norm([Wp2x Wp2y] – LAP(1:2));
else
% Rotate in place
y = [ Wp1(1,:) ; UAVState.x, UAVState.y, UAVState.z Steer(1); Wp2x , Wp2y , 0 , Steer(1) ];
DTD = norm([Wp2x Wp2y] – [UAVState.x, UAVState.y]);
needHover = true;
end
else
% If there is no good steer direction or UAV is too low, fly up
y = [ Wp1(1,:) ; UAVState.x , UAVState.y , UAVState.z-2 , 0 ; Wp2x , Wp2y , 0 , 0 ];
DTD = norm([Wp2x Wp2y] – [UAVState.x, UAVState.y]);
end
if(DTD<5)
% When close to target point, switch to landing
y = [ Wp1(1,:) ; Wp2x , Wp2y, -11 , 0 ; Wp2x , Wp2y , -1 , 0 ];
end
end
I get this obvious error when I try to run the simulation:
I have tried sending the sigal from the GCS dirrectly into the MissionData (as expected), but then the quadcopter just flies back and forth around the first waypoint of the mission:
I would very much appreciate any advice on how to move further with this.
Regards,
TudorHi,
I’m trying to modify the UAV Package Delivery project such as it allows multiple waypoints while avoiding obstacles, using QGroundConrol. Until now I have done these:
-modified replaced FollowWaypoints with the guidance from FullGuidanceLogic
However, MissionData input must be bus signal "uavPathManagerBus"
Currently, the MissionData comes from the function that contains the OA algorithm:
function [y, DTD, needHover] = computeLPWaypoints(mission, Steer,UAVState)
%#codegen
Wp1 = [mission(1).position’ mission(1).params(4)];
Wp2x = mission(2).position(1);
Wp2y = mission(2).position(2);
needHover = false;
% Follow obstacle avoidance steer direction when UAV is above 5 meters
% above ground
if (~any(isnan(Steer)) && (UAVState.z < -5))
if (Steer(5) == 0)
% Compute look ahead point 6 meters along the steering direction
LAP_local = 6*Steer(2:4)’;
% Follow yaw command from obstacle avoidance
yaw = Steer(1);
LAP = [LAP_local yaw] + [UAVState.x, UAVState.y, UAVState.z, 0];
if(isnan(LAP(4)))
LAP(4) = 0;
end
y = [ Wp1(1,:) ; LAP ; Wp2x , Wp2y , 0 , LAP(4) ];
DTD = norm([Wp2x Wp2y] – LAP(1:2));
else
% Rotate in place
y = [ Wp1(1,:) ; UAVState.x, UAVState.y, UAVState.z Steer(1); Wp2x , Wp2y , 0 , Steer(1) ];
DTD = norm([Wp2x Wp2y] – [UAVState.x, UAVState.y]);
needHover = true;
end
else
% If there is no good steer direction or UAV is too low, fly up
y = [ Wp1(1,:) ; UAVState.x , UAVState.y , UAVState.z-2 , 0 ; Wp2x , Wp2y , 0 , 0 ];
DTD = norm([Wp2x Wp2y] – [UAVState.x, UAVState.y]);
end
if(DTD<5)
% When close to target point, switch to landing
y = [ Wp1(1,:) ; Wp2x , Wp2y, -11 , 0 ; Wp2x , Wp2y , -1 , 0 ];
end
end
I get this obvious error when I try to run the simulation:
I have tried sending the sigal from the GCS dirrectly into the MissionData (as expected), but then the quadcopter just flies back and forth around the first waypoint of the mission:
I would very much appreciate any advice on how to move further with this.
Regards,
Tudor Hi,
I’m trying to modify the UAV Package Delivery project such as it allows multiple waypoints while avoiding obstacles, using QGroundConrol. Until now I have done these:
-modified replaced FollowWaypoints with the guidance from FullGuidanceLogic
However, MissionData input must be bus signal "uavPathManagerBus"
Currently, the MissionData comes from the function that contains the OA algorithm:
function [y, DTD, needHover] = computeLPWaypoints(mission, Steer,UAVState)
%#codegen
Wp1 = [mission(1).position’ mission(1).params(4)];
Wp2x = mission(2).position(1);
Wp2y = mission(2).position(2);
needHover = false;
% Follow obstacle avoidance steer direction when UAV is above 5 meters
% above ground
if (~any(isnan(Steer)) && (UAVState.z < -5))
if (Steer(5) == 0)
% Compute look ahead point 6 meters along the steering direction
LAP_local = 6*Steer(2:4)’;
% Follow yaw command from obstacle avoidance
yaw = Steer(1);
LAP = [LAP_local yaw] + [UAVState.x, UAVState.y, UAVState.z, 0];
if(isnan(LAP(4)))
LAP(4) = 0;
end
y = [ Wp1(1,:) ; LAP ; Wp2x , Wp2y , 0 , LAP(4) ];
DTD = norm([Wp2x Wp2y] – LAP(1:2));
else
% Rotate in place
y = [ Wp1(1,:) ; UAVState.x, UAVState.y, UAVState.z Steer(1); Wp2x , Wp2y , 0 , Steer(1) ];
DTD = norm([Wp2x Wp2y] – [UAVState.x, UAVState.y]);
needHover = true;
end
else
% If there is no good steer direction or UAV is too low, fly up
y = [ Wp1(1,:) ; UAVState.x , UAVState.y , UAVState.z-2 , 0 ; Wp2x , Wp2y , 0 , 0 ];
DTD = norm([Wp2x Wp2y] – [UAVState.x, UAVState.y]);
end
if(DTD<5)
% When close to target point, switch to landing
y = [ Wp1(1,:) ; Wp2x , Wp2y, -11 , 0 ; Wp2x , Wp2y , -1 , 0 ];
end
end
I get this obvious error when I try to run the simulation:
I have tried sending the sigal from the GCS dirrectly into the MissionData (as expected), but then the quadcopter just flies back and forth around the first waypoint of the mission:
I would very much appreciate any advice on how to move further with this.
Regards,
Tudor uav, uav package delivery, bus, embedded matlab function, matlab function, signal, obstacle avoidance, uav toolbox MATLAB Answers — New Questions
Simulink Arduino Support Package – No appropriate method, property, or field…/can’t connect to server keeps occuring despite trying answers
After installing R2024a, I can’t get the package working. Multiple times unistalled, reinstalled, MATLAB always run in admin mode, tried clean installation (after deleting files in ProgramData/…/SupportPackages). Connection test gives the message (attached screenshot):
No appropriate method, property, or field… for the class …
Trying to run simple program to read encoder in simulink says it can’t connect to server, even though the setup of arduino is fine, multiple times checked. Other blocks give the same error. Attached screenshot of error after trying to read from digital pin.
Same programs and setup worked on R2021b, although after some time the inputs from digital pins dropped to constant 0 and wouldn’t work again until restarting matlab and simulink.
Not mentioning that the installation itself is unfriedly too, I always have to uninstall all support packages, clean ProgramData..SupportPackages…After installing R2024a, I can’t get the package working. Multiple times unistalled, reinstalled, MATLAB always run in admin mode, tried clean installation (after deleting files in ProgramData/…/SupportPackages). Connection test gives the message (attached screenshot):
No appropriate method, property, or field… for the class …
Trying to run simple program to read encoder in simulink says it can’t connect to server, even though the setup of arduino is fine, multiple times checked. Other blocks give the same error. Attached screenshot of error after trying to read from digital pin.
Same programs and setup worked on R2021b, although after some time the inputs from digital pins dropped to constant 0 and wouldn’t work again until restarting matlab and simulink.
Not mentioning that the installation itself is unfriedly too, I always have to uninstall all support packages, clean ProgramData..SupportPackages… After installing R2024a, I can’t get the package working. Multiple times unistalled, reinstalled, MATLAB always run in admin mode, tried clean installation (after deleting files in ProgramData/…/SupportPackages). Connection test gives the message (attached screenshot):
No appropriate method, property, or field… for the class …
Trying to run simple program to read encoder in simulink says it can’t connect to server, even though the setup of arduino is fine, multiple times checked. Other blocks give the same error. Attached screenshot of error after trying to read from digital pin.
Same programs and setup worked on R2021b, although after some time the inputs from digital pins dropped to constant 0 and wouldn’t work again until restarting matlab and simulink.
Not mentioning that the installation itself is unfriedly too, I always have to uninstall all support packages, clean ProgramData..SupportPackages… arduino, simulink arduino MATLAB Answers — New Questions
Hypergeometric functions(1F2) in matlab
I want to use the hypergeometric function [def] this exists in mathematica (wolfram). I tried this
function result = hypegeo(q, r)
qr = q * r;
z = – (qr)^2 / 4;
inp=[3/2,[1, 5/2],z];
F2_value = hypergeom(1,2,inp);
result = (1/3) * F2_value;
end
but for me looking at the definition of the hyper geometric function in matlab doesnt seem exaclty the same as the one in wolfram.
if they arent the same, is there a way to use mathmatica functions in matlab or some other workaround for this?I want to use the hypergeometric function [def] this exists in mathematica (wolfram). I tried this
function result = hypegeo(q, r)
qr = q * r;
z = – (qr)^2 / 4;
inp=[3/2,[1, 5/2],z];
F2_value = hypergeom(1,2,inp);
result = (1/3) * F2_value;
end
but for me looking at the definition of the hyper geometric function in matlab doesnt seem exaclty the same as the one in wolfram.
if they arent the same, is there a way to use mathmatica functions in matlab or some other workaround for this? I want to use the hypergeometric function [def] this exists in mathematica (wolfram). I tried this
function result = hypegeo(q, r)
qr = q * r;
z = – (qr)^2 / 4;
inp=[3/2,[1, 5/2],z];
F2_value = hypergeom(1,2,inp);
result = (1/3) * F2_value;
end
but for me looking at the definition of the hyper geometric function in matlab doesnt seem exaclty the same as the one in wolfram.
if they arent the same, is there a way to use mathmatica functions in matlab or some other workaround for this? hypergeometric function, wolfram MATLAB Answers — New Questions
2018a version neeeded
I need the R2018a version for my project ,some tools in that are not available in the current version.how can Idownload the 2018 version .can a direct link be providedI need the R2018a version for my project ,some tools in that are not available in the current version.how can Idownload the 2018 version .can a direct link be provided I need the R2018a version for my project ,some tools in that are not available in the current version.how can Idownload the 2018 version .can a direct link be provided #2018a download MATLAB Answers — New Questions
Incosistency Precision Value (decimal double) When using strcmpi/contains
Hi guys, im facing trouble when I want to compare string using ‘strcmpi’ or ‘contains’. The problem is when I convert string to double, Its precision value sometimes are not concictency like picture as I shown below :
how do I fix this ?Hi guys, im facing trouble when I want to compare string using ‘strcmpi’ or ‘contains’. The problem is when I convert string to double, Its precision value sometimes are not concictency like picture as I shown below :
how do I fix this ? Hi guys, im facing trouble when I want to compare string using ‘strcmpi’ or ‘contains’. The problem is when I convert string to double, Its precision value sometimes are not concictency like picture as I shown below :
how do I fix this ? precision, decimal, contains, strcmpi, strcmp MATLAB Answers — New Questions
I want to calculate velocity. How do I apply my code to all tables in all cells?
Hi,
I have a data set of distances (see "results_distances" attached) and want to calculate the velocity for each row in each table in each cell.
I have the following code:
results_velocity = cell(size(results_distances));
for i = 1:length(results_distances) % iterate over tables in cell array
if ~isempty(results_distances{i}) % check if table is not empty
table_data = results_distances{i};
v_table = table_data; % initialize output table with the same size as input table
% Calculate velocity for each numeric variable (column) in the table
for var = 1:width(table_data)
% Check if the variable is numeric
if isnumeric(table_data{:, var})
% Calculate velocity for each row
for row = 2:size(table_data, 1)
% Subtract previous value from current value and divide by time_interval
v_table{row, var} = (table_data{row, var} – table_data{row-1, var}) / time_interval;
end
end
end
results_velocity{i} = v_table; % store velocity table in output cell array
end
end
However, when I run my code, it seems to only apply the calculation to the first column of tables in the cell array (see "results_velocity"). What am I doing wrong?
Thanks!Hi,
I have a data set of distances (see "results_distances" attached) and want to calculate the velocity for each row in each table in each cell.
I have the following code:
results_velocity = cell(size(results_distances));
for i = 1:length(results_distances) % iterate over tables in cell array
if ~isempty(results_distances{i}) % check if table is not empty
table_data = results_distances{i};
v_table = table_data; % initialize output table with the same size as input table
% Calculate velocity for each numeric variable (column) in the table
for var = 1:width(table_data)
% Check if the variable is numeric
if isnumeric(table_data{:, var})
% Calculate velocity for each row
for row = 2:size(table_data, 1)
% Subtract previous value from current value and divide by time_interval
v_table{row, var} = (table_data{row, var} – table_data{row-1, var}) / time_interval;
end
end
end
results_velocity{i} = v_table; % store velocity table in output cell array
end
end
However, when I run my code, it seems to only apply the calculation to the first column of tables in the cell array (see "results_velocity"). What am I doing wrong?
Thanks! Hi,
I have a data set of distances (see "results_distances" attached) and want to calculate the velocity for each row in each table in each cell.
I have the following code:
results_velocity = cell(size(results_distances));
for i = 1:length(results_distances) % iterate over tables in cell array
if ~isempty(results_distances{i}) % check if table is not empty
table_data = results_distances{i};
v_table = table_data; % initialize output table with the same size as input table
% Calculate velocity for each numeric variable (column) in the table
for var = 1:width(table_data)
% Check if the variable is numeric
if isnumeric(table_data{:, var})
% Calculate velocity for each row
for row = 2:size(table_data, 1)
% Subtract previous value from current value and divide by time_interval
v_table{row, var} = (table_data{row, var} – table_data{row-1, var}) / time_interval;
end
end
end
results_velocity{i} = v_table; % store velocity table in output cell array
end
end
However, when I run my code, it seems to only apply the calculation to the first column of tables in the cell array (see "results_velocity"). What am I doing wrong?
Thanks! velocity, distances, tables, cells, cell array MATLAB Answers — New Questions
Passing output from a ButtonDownFcn callback function
Hello,
I am struggling with figuring out how to pass variables from a callback function (using ButtonDownFcn) to my main script.
Below is a simple example where I am trying to modify the example script from:
https://nl.mathworks.com/help/images/measure-distances-in-images.html
I simplified it below to just make the first function work and have two examples below:
– the original line (LINE A below), which doesn’t pass my variable back and doesn’t seem to allow me to define further output variables. Adding variables (double) to hIm also doesn’t work (I guess because it is an image object?)
– the simple line (LINE B below) works to pass the output variable, but is not an option because it doesn’t use the ButtonDownFcn anymore (which I need later).
clear all
close all
clc
im = imread(‘SENIAM_EMGEP1.jpeg’);
% Gather data about the image, such as its size, and store the data in a structure that you can pass to callback functions.
sz = size(im);
myData.Units = ‘pixels’;
myData.MaxValue = hypot(sz(1),sz(2));
myData.Colormap = hot;
myData.ScaleFactor = 1;
% Display the image in an axes.
hIm = imshow(im);
% Specify a callback function for the ButtonDownFcn callback on the image. Pass the myData structure to the callback function. This callback function creates the line objects and starts drawing the ROIs.
hIm.ButtonDownFcn = @(~,~) startDrawing(hIm.Parent,myData); %% LINE A
myData = startDrawing(hIm.Parent,myData); %% LINE B
function myData = startDrawing(hAx,myData)
myData.test = 2;
% Create a line ROI object. Specify the initial color of the line and
% store the |myData| structure in the |UserData| property of the ROI.
h = images.roi.Line(‘Color’,[0, 0, 0.5625],’UserData’,myData);
end
I have had a similar issue with callback functions and thought it was time to seek help.
The answer provided here (https://nl.mathworks.com/matlabcentral/answers/563102-passing-a-variable-from-a-call-back-function-matlab-2020a) doesn’t allow me to figure it out and I want to avoid using global variables.
Thanks for any advice.Hello,
I am struggling with figuring out how to pass variables from a callback function (using ButtonDownFcn) to my main script.
Below is a simple example where I am trying to modify the example script from:
https://nl.mathworks.com/help/images/measure-distances-in-images.html
I simplified it below to just make the first function work and have two examples below:
– the original line (LINE A below), which doesn’t pass my variable back and doesn’t seem to allow me to define further output variables. Adding variables (double) to hIm also doesn’t work (I guess because it is an image object?)
– the simple line (LINE B below) works to pass the output variable, but is not an option because it doesn’t use the ButtonDownFcn anymore (which I need later).
clear all
close all
clc
im = imread(‘SENIAM_EMGEP1.jpeg’);
% Gather data about the image, such as its size, and store the data in a structure that you can pass to callback functions.
sz = size(im);
myData.Units = ‘pixels’;
myData.MaxValue = hypot(sz(1),sz(2));
myData.Colormap = hot;
myData.ScaleFactor = 1;
% Display the image in an axes.
hIm = imshow(im);
% Specify a callback function for the ButtonDownFcn callback on the image. Pass the myData structure to the callback function. This callback function creates the line objects and starts drawing the ROIs.
hIm.ButtonDownFcn = @(~,~) startDrawing(hIm.Parent,myData); %% LINE A
myData = startDrawing(hIm.Parent,myData); %% LINE B
function myData = startDrawing(hAx,myData)
myData.test = 2;
% Create a line ROI object. Specify the initial color of the line and
% store the |myData| structure in the |UserData| property of the ROI.
h = images.roi.Line(‘Color’,[0, 0, 0.5625],’UserData’,myData);
end
I have had a similar issue with callback functions and thought it was time to seek help.
The answer provided here (https://nl.mathworks.com/matlabcentral/answers/563102-passing-a-variable-from-a-call-back-function-matlab-2020a) doesn’t allow me to figure it out and I want to avoid using global variables.
Thanks for any advice. Hello,
I am struggling with figuring out how to pass variables from a callback function (using ButtonDownFcn) to my main script.
Below is a simple example where I am trying to modify the example script from:
https://nl.mathworks.com/help/images/measure-distances-in-images.html
I simplified it below to just make the first function work and have two examples below:
– the original line (LINE A below), which doesn’t pass my variable back and doesn’t seem to allow me to define further output variables. Adding variables (double) to hIm also doesn’t work (I guess because it is an image object?)
– the simple line (LINE B below) works to pass the output variable, but is not an option because it doesn’t use the ButtonDownFcn anymore (which I need later).
clear all
close all
clc
im = imread(‘SENIAM_EMGEP1.jpeg’);
% Gather data about the image, such as its size, and store the data in a structure that you can pass to callback functions.
sz = size(im);
myData.Units = ‘pixels’;
myData.MaxValue = hypot(sz(1),sz(2));
myData.Colormap = hot;
myData.ScaleFactor = 1;
% Display the image in an axes.
hIm = imshow(im);
% Specify a callback function for the ButtonDownFcn callback on the image. Pass the myData structure to the callback function. This callback function creates the line objects and starts drawing the ROIs.
hIm.ButtonDownFcn = @(~,~) startDrawing(hIm.Parent,myData); %% LINE A
myData = startDrawing(hIm.Parent,myData); %% LINE B
function myData = startDrawing(hAx,myData)
myData.test = 2;
% Create a line ROI object. Specify the initial color of the line and
% store the |myData| structure in the |UserData| property of the ROI.
h = images.roi.Line(‘Color’,[0, 0, 0.5625],’UserData’,myData);
end
I have had a similar issue with callback functions and thought it was time to seek help.
The answer provided here (https://nl.mathworks.com/matlabcentral/answers/563102-passing-a-variable-from-a-call-back-function-matlab-2020a) doesn’t allow me to figure it out and I want to avoid using global variables.
Thanks for any advice. callback, passing variables MATLAB Answers — New Questions
inv(A)*B or AB, which is more accurate for a full rank A and half rank B
My matrix is
>> A_2stepblock
A_2stepblock =
1.0e+06 *
Columns 1 through 6
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0.000024000000000
1.953050781823359 0.390611805629631 0.078122690980311 0.015624604167218 0.003124934027730 0.000624989444415
3.515506250666680 0.624981527842487 0.109372229170523 0.018749604166382 0.003124947222073 0.000499993666635
5.624833750582380 0.874977833364188 0.131247229164674 0.018749683332437 0.002499968333177 0.000299997466649
7.874800500277688 1.049977833317391 0.131247783327059 0.014999809999061 0.001499987333244 0.000119999493329
9.449800499856519 1.049982266616475 0.104998669993428 0.008999923999464 0.000599997466643 0.000024000000000
Columns 7 through 10
0 0 0 0.000001000000000
0 0 0.000001000000000 0
0 0.000002000000000 0 0
0.000006000000000 0 0 0
0 0 0 0
0.000124998416659 0.000024999788887 0.000004999978889 0.000001000000000
0.000074999366662 0.000009999957777 0.000001000000000 0
0.000029999873332 0.000002000000000 0 0
0.000006000000000 0 0 0
0 0 0 0
K>> rank(A_2stepblock)
ans =
10
and I need to calculate
A_2stepblock dA_2stepblock_dt / A_2stepblock
where
K>> dA_2stepblock_dt
dA_2stepblock_dt =
1.0e+06 *
Columns 1 through 7
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
3.515506250666680 0.624981527842487 0.109372229170523 0.018749604166382 0.003124947222073 0.000499993666635 0.000074999366662
5.624833750582380 0.874977833364188 0.131247229164674 0.018749683332437 0.002499968333177 0.000299997466649 0.000029999873332
7.874800500277688 1.049977833317391 0.131247783327059 0.014999809999061 0.001499987333244 0.000119999493329 0.000006000000000
9.449800499856519 1.049982266616475 0.104998669993428 0.008999923999464 0.000599997466643 0.000024000000000 0
9.449840399548277 0.839989359947423 0.062999467996248 0.003599984799861 0.000120000000000 0 0
Columns 8 through 10
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0.000009999957777 0.000001000000000 0
0.000002000000000 0 0
0 0 0
0 0 0
0 0 0
has a rank of 5.
I tried both inv() and /, resulting in very different results for a gradient descent algorithm.
So, which is more accurate?My matrix is
>> A_2stepblock
A_2stepblock =
1.0e+06 *
Columns 1 through 6
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0.000024000000000
1.953050781823359 0.390611805629631 0.078122690980311 0.015624604167218 0.003124934027730 0.000624989444415
3.515506250666680 0.624981527842487 0.109372229170523 0.018749604166382 0.003124947222073 0.000499993666635
5.624833750582380 0.874977833364188 0.131247229164674 0.018749683332437 0.002499968333177 0.000299997466649
7.874800500277688 1.049977833317391 0.131247783327059 0.014999809999061 0.001499987333244 0.000119999493329
9.449800499856519 1.049982266616475 0.104998669993428 0.008999923999464 0.000599997466643 0.000024000000000
Columns 7 through 10
0 0 0 0.000001000000000
0 0 0.000001000000000 0
0 0.000002000000000 0 0
0.000006000000000 0 0 0
0 0 0 0
0.000124998416659 0.000024999788887 0.000004999978889 0.000001000000000
0.000074999366662 0.000009999957777 0.000001000000000 0
0.000029999873332 0.000002000000000 0 0
0.000006000000000 0 0 0
0 0 0 0
K>> rank(A_2stepblock)
ans =
10
and I need to calculate
A_2stepblock dA_2stepblock_dt / A_2stepblock
where
K>> dA_2stepblock_dt
dA_2stepblock_dt =
1.0e+06 *
Columns 1 through 7
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
3.515506250666680 0.624981527842487 0.109372229170523 0.018749604166382 0.003124947222073 0.000499993666635 0.000074999366662
5.624833750582380 0.874977833364188 0.131247229164674 0.018749683332437 0.002499968333177 0.000299997466649 0.000029999873332
7.874800500277688 1.049977833317391 0.131247783327059 0.014999809999061 0.001499987333244 0.000119999493329 0.000006000000000
9.449800499856519 1.049982266616475 0.104998669993428 0.008999923999464 0.000599997466643 0.000024000000000 0
9.449840399548277 0.839989359947423 0.062999467996248 0.003599984799861 0.000120000000000 0 0
Columns 8 through 10
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0.000009999957777 0.000001000000000 0
0.000002000000000 0 0
0 0 0
0 0 0
0 0 0
has a rank of 5.
I tried both inv() and /, resulting in very different results for a gradient descent algorithm.
So, which is more accurate? My matrix is
>> A_2stepblock
A_2stepblock =
1.0e+06 *
Columns 1 through 6
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0.000024000000000
1.953050781823359 0.390611805629631 0.078122690980311 0.015624604167218 0.003124934027730 0.000624989444415
3.515506250666680 0.624981527842487 0.109372229170523 0.018749604166382 0.003124947222073 0.000499993666635
5.624833750582380 0.874977833364188 0.131247229164674 0.018749683332437 0.002499968333177 0.000299997466649
7.874800500277688 1.049977833317391 0.131247783327059 0.014999809999061 0.001499987333244 0.000119999493329
9.449800499856519 1.049982266616475 0.104998669993428 0.008999923999464 0.000599997466643 0.000024000000000
Columns 7 through 10
0 0 0 0.000001000000000
0 0 0.000001000000000 0
0 0.000002000000000 0 0
0.000006000000000 0 0 0
0 0 0 0
0.000124998416659 0.000024999788887 0.000004999978889 0.000001000000000
0.000074999366662 0.000009999957777 0.000001000000000 0
0.000029999873332 0.000002000000000 0 0
0.000006000000000 0 0 0
0 0 0 0
K>> rank(A_2stepblock)
ans =
10
and I need to calculate
A_2stepblock dA_2stepblock_dt / A_2stepblock
where
K>> dA_2stepblock_dt
dA_2stepblock_dt =
1.0e+06 *
Columns 1 through 7
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
3.515506250666680 0.624981527842487 0.109372229170523 0.018749604166382 0.003124947222073 0.000499993666635 0.000074999366662
5.624833750582380 0.874977833364188 0.131247229164674 0.018749683332437 0.002499968333177 0.000299997466649 0.000029999873332
7.874800500277688 1.049977833317391 0.131247783327059 0.014999809999061 0.001499987333244 0.000119999493329 0.000006000000000
9.449800499856519 1.049982266616475 0.104998669993428 0.008999923999464 0.000599997466643 0.000024000000000 0
9.449840399548277 0.839989359947423 0.062999467996248 0.003599984799861 0.000120000000000 0 0
Columns 8 through 10
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0.000009999957777 0.000001000000000 0
0.000002000000000 0 0
0 0 0
0 0 0
0 0 0
has a rank of 5.
I tried both inv() and /, resulting in very different results for a gradient descent algorithm.
So, which is more accurate? matrix inverse, linear algebra MATLAB Answers — New Questions
How do I get LDAP user information for logged in user into my MATLAB WebApp?
I have a WebApp server (Windows, R2022a) running a couple of apps, and it is behind LDAP authentication. When a user logs in, I can see that the user information is stored somewhere within the server because the correct username appears in the upper right corner of the main MATLAB WebApp server screen. What I would like to do is access that information inside my app. Is there a MATLAB command within the app that can access the logged in user? I tried:
user = compiler.UserInfo()
but all the fields were empty.
Thank you!
-GregI have a WebApp server (Windows, R2022a) running a couple of apps, and it is behind LDAP authentication. When a user logs in, I can see that the user information is stored somewhere within the server because the correct username appears in the upper right corner of the main MATLAB WebApp server screen. What I would like to do is access that information inside my app. Is there a MATLAB command within the app that can access the logged in user? I tried:
user = compiler.UserInfo()
but all the fields were empty.
Thank you!
-Greg I have a WebApp server (Windows, R2022a) running a couple of apps, and it is behind LDAP authentication. When a user logs in, I can see that the user information is stored somewhere within the server because the correct username appears in the upper right corner of the main MATLAB WebApp server screen. What I would like to do is access that information inside my app. Is there a MATLAB command within the app that can access the logged in user? I tried:
user = compiler.UserInfo()
but all the fields were empty.
Thank you!
-Greg ldap, webapp server MATLAB Answers — New Questions
Does Matlab support system objects for X410 USRP?
Does Matlab R2024a support system objects such as comm.SDRuTransmitter or comm.SDRuReceiver with the X410 USRP when using Wireless TestBench? If not, is this something that will be available in future updates?Does Matlab R2024a support system objects such as comm.SDRuTransmitter or comm.SDRuReceiver with the X410 USRP when using Wireless TestBench? If not, is this something that will be available in future updates? Does Matlab R2024a support system objects such as comm.SDRuTransmitter or comm.SDRuReceiver with the X410 USRP when using Wireless TestBench? If not, is this something that will be available in future updates? usrp, matlab, sdr MATLAB Answers — New Questions
UIFigure appearance (scaling) change between 2023b and 2024a
I wrote an app in 2023b, but after installing 2024a the figure doesn’t appear the same, and some of my UI controls actually fall off the figure in 2024a. Below is a simplified example of the issue.
Here is the code I ran in both versions:
fig = uifigure(Name="This is in 2023b");
% fig = uifigure(Name="This is in 2024a");
lbl = uilabel(fig);
lbl.Text = "This is a label";
lbl.Position = [20 200 100 60];
Here is a screenshot of the outputs side-by-side:
As you can see the font and the spacing in 2024a is slightly larger, as if it is scaled differently. And it’s not just with UILables, the size and spacing is larger for all objects in 2024a compared to 2023b.
I reset all default groot settings with reset(groot, "default")
I recursivly cleared all personal settings with [setting].clearPersonalValue
But I still get this result.
It’s a fairly large and complex app with a lot of ui controls and I don’t want to rewrite it because if this.
Is there a setting somewhere I’m overlooking, or something else I’m missing?I wrote an app in 2023b, but after installing 2024a the figure doesn’t appear the same, and some of my UI controls actually fall off the figure in 2024a. Below is a simplified example of the issue.
Here is the code I ran in both versions:
fig = uifigure(Name="This is in 2023b");
% fig = uifigure(Name="This is in 2024a");
lbl = uilabel(fig);
lbl.Text = "This is a label";
lbl.Position = [20 200 100 60];
Here is a screenshot of the outputs side-by-side:
As you can see the font and the spacing in 2024a is slightly larger, as if it is scaled differently. And it’s not just with UILables, the size and spacing is larger for all objects in 2024a compared to 2023b.
I reset all default groot settings with reset(groot, "default")
I recursivly cleared all personal settings with [setting].clearPersonalValue
But I still get this result.
It’s a fairly large and complex app with a lot of ui controls and I don’t want to rewrite it because if this.
Is there a setting somewhere I’m overlooking, or something else I’m missing? I wrote an app in 2023b, but after installing 2024a the figure doesn’t appear the same, and some of my UI controls actually fall off the figure in 2024a. Below is a simplified example of the issue.
Here is the code I ran in both versions:
fig = uifigure(Name="This is in 2023b");
% fig = uifigure(Name="This is in 2024a");
lbl = uilabel(fig);
lbl.Text = "This is a label";
lbl.Position = [20 200 100 60];
Here is a screenshot of the outputs side-by-side:
As you can see the font and the spacing in 2024a is slightly larger, as if it is scaled differently. And it’s not just with UILables, the size and spacing is larger for all objects in 2024a compared to 2023b.
I reset all default groot settings with reset(groot, "default")
I recursivly cleared all personal settings with [setting].clearPersonalValue
But I still get this result.
It’s a fairly large and complex app with a lot of ui controls and I don’t want to rewrite it because if this.
Is there a setting somewhere I’m overlooking, or something else I’m missing? uifigure, settings, groot, uifigure font, uifigure scaling MATLAB Answers — New Questions
How to save the values of data tips of a plot
What function to use to save the data tip values of a plot to some variables in my app designerWhat function to use to save the data tip values of a plot to some variables in my app designer What function to use to save the data tip values of a plot to some variables in my app designer datatips MATLAB Answers — New Questions
Multivariate Newthon’s Method
Dear All,
I am trying to solve a multivariate function by using the Newthon’s Method. However, I get an error message in the lwhen I run my code (exactly in newtons_method file), and I could not figure out what is going on. Here is the files that I am using:
%This file is the one that appears here: Multivariate Newton’s Method (newtons_method_n)
function [x,k,x_all] = newtons_method_n(f,J,x0,opts)
if (nargin < 4) || isempty(opts) || ~isfield(opts,’k_max’)
k_max = 200;
else
k_max = opts.k_max;
end
if (nargin < 4) || isempty(opts) || ~isfield(opts,’return_all’)
return_all = false;
else
return_all = opts.return_all;
end
if (nargin < 4) || isempty(opts) || ~isfield(opts,’TOL’)
TOL = 1e-10;
else
TOL = opts.TOL;
end
n = length(x0);
if f(x0) == zeros(n,1)
x = x0;
return
end
x_curr = x0;
x_next = zeros(n,1);
if return_all
x_all = zeros(n,k_max+1);
end
for k = 1:k_max
if return_all
x_all(:,k) = x_curr;
end
y = J(x_curr)(-f(x_curr));
x_next = x_curr+y;
if (norm(y) < TOL)
break;
end
x_curr = x_next;
end
x = x_next;
if return_all
x_all(:,k+1) = x;
x_all = x_all(:,1:(k+1));
end
end
This is the main.n file:
clear all
clc
% Global variables are only parameters which do not change
global a b theta t d n L Y g
load DATA
n = 19; % Number of countries
a = 0.134813590592666;
b = 0.21221;
theta = 8.28; % Shape of Pareto dist
relaw = aw./aw(n,1); % Relative wage to US
t = exp( b*(S+theta*(log(relaw))) ); % Technology: see Table VI
d = D; % Geographic barriers dni^(-theta)
L = l; % Labor
Y = y; % Income
elast = 0.1; % Elasticity of wage adjustment
% Gamma constant (as in the original code)
g = (b^(-b))*((1-b)^(-(1-b)));
g = g^(theta);
disp(‘Newton iterative procedure starts here’)
w = aw; % Set initial wages at data
% Set bounds (implied by the model) for prices
pbounds = bounds(w);
p0 = 0.5*(pbounds(:,1)+pbounds(:,2)); % Half way between min and max
[pval,fval] = newtons_method(@(p) prices(p,w),p0);
And finally the prices.m file:
function [fval,fjac] = prices(p,w)
global b theta t d n g
aux1 = g*t.*(w.^(-theta*b));
aux2 = repmat(aux1,1,n)’;
G = d.*aux2;
fval = Gp -p.^(1-b);
fjac = inv(G) – (1-b)*diag(p.^(-b));
With all this on hand, any idea about why is there an error?
Thank you in advanced!Dear All,
I am trying to solve a multivariate function by using the Newthon’s Method. However, I get an error message in the lwhen I run my code (exactly in newtons_method file), and I could not figure out what is going on. Here is the files that I am using:
%This file is the one that appears here: Multivariate Newton’s Method (newtons_method_n)
function [x,k,x_all] = newtons_method_n(f,J,x0,opts)
if (nargin < 4) || isempty(opts) || ~isfield(opts,’k_max’)
k_max = 200;
else
k_max = opts.k_max;
end
if (nargin < 4) || isempty(opts) || ~isfield(opts,’return_all’)
return_all = false;
else
return_all = opts.return_all;
end
if (nargin < 4) || isempty(opts) || ~isfield(opts,’TOL’)
TOL = 1e-10;
else
TOL = opts.TOL;
end
n = length(x0);
if f(x0) == zeros(n,1)
x = x0;
return
end
x_curr = x0;
x_next = zeros(n,1);
if return_all
x_all = zeros(n,k_max+1);
end
for k = 1:k_max
if return_all
x_all(:,k) = x_curr;
end
y = J(x_curr)(-f(x_curr));
x_next = x_curr+y;
if (norm(y) < TOL)
break;
end
x_curr = x_next;
end
x = x_next;
if return_all
x_all(:,k+1) = x;
x_all = x_all(:,1:(k+1));
end
end
This is the main.n file:
clear all
clc
% Global variables are only parameters which do not change
global a b theta t d n L Y g
load DATA
n = 19; % Number of countries
a = 0.134813590592666;
b = 0.21221;
theta = 8.28; % Shape of Pareto dist
relaw = aw./aw(n,1); % Relative wage to US
t = exp( b*(S+theta*(log(relaw))) ); % Technology: see Table VI
d = D; % Geographic barriers dni^(-theta)
L = l; % Labor
Y = y; % Income
elast = 0.1; % Elasticity of wage adjustment
% Gamma constant (as in the original code)
g = (b^(-b))*((1-b)^(-(1-b)));
g = g^(theta);
disp(‘Newton iterative procedure starts here’)
w = aw; % Set initial wages at data
% Set bounds (implied by the model) for prices
pbounds = bounds(w);
p0 = 0.5*(pbounds(:,1)+pbounds(:,2)); % Half way between min and max
[pval,fval] = newtons_method(@(p) prices(p,w),p0);
And finally the prices.m file:
function [fval,fjac] = prices(p,w)
global b theta t d n g
aux1 = g*t.*(w.^(-theta*b));
aux2 = repmat(aux1,1,n)’;
G = d.*aux2;
fval = Gp -p.^(1-b);
fjac = inv(G) – (1-b)*diag(p.^(-b));
With all this on hand, any idea about why is there an error?
Thank you in advanced! Dear All,
I am trying to solve a multivariate function by using the Newthon’s Method. However, I get an error message in the lwhen I run my code (exactly in newtons_method file), and I could not figure out what is going on. Here is the files that I am using:
%This file is the one that appears here: Multivariate Newton’s Method (newtons_method_n)
function [x,k,x_all] = newtons_method_n(f,J,x0,opts)
if (nargin < 4) || isempty(opts) || ~isfield(opts,’k_max’)
k_max = 200;
else
k_max = opts.k_max;
end
if (nargin < 4) || isempty(opts) || ~isfield(opts,’return_all’)
return_all = false;
else
return_all = opts.return_all;
end
if (nargin < 4) || isempty(opts) || ~isfield(opts,’TOL’)
TOL = 1e-10;
else
TOL = opts.TOL;
end
n = length(x0);
if f(x0) == zeros(n,1)
x = x0;
return
end
x_curr = x0;
x_next = zeros(n,1);
if return_all
x_all = zeros(n,k_max+1);
end
for k = 1:k_max
if return_all
x_all(:,k) = x_curr;
end
y = J(x_curr)(-f(x_curr));
x_next = x_curr+y;
if (norm(y) < TOL)
break;
end
x_curr = x_next;
end
x = x_next;
if return_all
x_all(:,k+1) = x;
x_all = x_all(:,1:(k+1));
end
end
This is the main.n file:
clear all
clc
% Global variables are only parameters which do not change
global a b theta t d n L Y g
load DATA
n = 19; % Number of countries
a = 0.134813590592666;
b = 0.21221;
theta = 8.28; % Shape of Pareto dist
relaw = aw./aw(n,1); % Relative wage to US
t = exp( b*(S+theta*(log(relaw))) ); % Technology: see Table VI
d = D; % Geographic barriers dni^(-theta)
L = l; % Labor
Y = y; % Income
elast = 0.1; % Elasticity of wage adjustment
% Gamma constant (as in the original code)
g = (b^(-b))*((1-b)^(-(1-b)));
g = g^(theta);
disp(‘Newton iterative procedure starts here’)
w = aw; % Set initial wages at data
% Set bounds (implied by the model) for prices
pbounds = bounds(w);
p0 = 0.5*(pbounds(:,1)+pbounds(:,2)); % Half way between min and max
[pval,fval] = newtons_method(@(p) prices(p,w),p0);
And finally the prices.m file:
function [fval,fjac] = prices(p,w)
global b theta t d n g
aux1 = g*t.*(w.^(-theta*b));
aux2 = repmat(aux1,1,n)’;
G = d.*aux2;
fval = Gp -p.^(1-b);
fjac = inv(G) – (1-b)*diag(p.^(-b));
With all this on hand, any idea about why is there an error?
Thank you in advanced! optimization, functions MATLAB Answers — New Questions