Category: Matlab
Category Archives: Matlab
Speeding up interpolation with scattered interpolation
Hi,
I’ve been working on speeding up my code for a project and I’ve identified that I’m spending a lot of time interpolating my data. I have data for wind speeds, air temperature, pressure and a few other things that depend on position in the X,Y and Z directions. I’ve been using ScatteredInterpolation to interpolate across 1425 data points and then using the interpolant find the wind speeds, air temperature, pressure etc. at a specific position. I was wondering if there was a faster way to do this, either speeding up scatteredinterpolation or a different interpolating method. Am fairly new to MATLAB so help appreciated.
Thanks.Hi,
I’ve been working on speeding up my code for a project and I’ve identified that I’m spending a lot of time interpolating my data. I have data for wind speeds, air temperature, pressure and a few other things that depend on position in the X,Y and Z directions. I’ve been using ScatteredInterpolation to interpolate across 1425 data points and then using the interpolant find the wind speeds, air temperature, pressure etc. at a specific position. I was wondering if there was a faster way to do this, either speeding up scatteredinterpolation or a different interpolating method. Am fairly new to MATLAB so help appreciated.
Thanks. Hi,
I’ve been working on speeding up my code for a project and I’ve identified that I’m spending a lot of time interpolating my data. I have data for wind speeds, air temperature, pressure and a few other things that depend on position in the X,Y and Z directions. I’ve been using ScatteredInterpolation to interpolate across 1425 data points and then using the interpolant find the wind speeds, air temperature, pressure etc. at a specific position. I was wondering if there was a faster way to do this, either speeding up scatteredinterpolation or a different interpolating method. Am fairly new to MATLAB so help appreciated.
Thanks. interpolation MATLAB Answers — New Questions
How to enter a sigmoidal equation for a curve fit with lsqfitting
he tratado de ingresar esta ecuación sigmoidal para un ajunste de curva lsqcurvefit con esta ecuación
y=1/(1+exp(4a(b-X)+2))
fun=@(x,xdata)1./(1+exp(4.*x(1).*(x(2) – xdata)+2))
x=lsqcurvefit(fun,x0,xdata,ydata)
he podido leer los datos aunque no he podido hacer los ajustes, al parecer reconoce al exponecial pero no los ajuste con X(1) y x(2).
alquien me podra ayudar con este temahe tratado de ingresar esta ecuación sigmoidal para un ajunste de curva lsqcurvefit con esta ecuación
y=1/(1+exp(4a(b-X)+2))
fun=@(x,xdata)1./(1+exp(4.*x(1).*(x(2) – xdata)+2))
x=lsqcurvefit(fun,x0,xdata,ydata)
he podido leer los datos aunque no he podido hacer los ajustes, al parecer reconoce al exponecial pero no los ajuste con X(1) y x(2).
alquien me podra ayudar con este tema he tratado de ingresar esta ecuación sigmoidal para un ajunste de curva lsqcurvefit con esta ecuación
y=1/(1+exp(4a(b-X)+2))
fun=@(x,xdata)1./(1+exp(4.*x(1).*(x(2) – xdata)+2))
x=lsqcurvefit(fun,x0,xdata,ydata)
he podido leer los datos aunque no he podido hacer los ajustes, al parecer reconoce al exponecial pero no los ajuste con X(1) y x(2).
alquien me podra ayudar con este tema curve fitting, sigmoid, fitnlm MATLAB Answers — New Questions
Speeding up interpolation with scattered interpolation
Hi,
I’ve been working on speeding up my code for a project and I’ve identified that I’m spending a lot of time interpolating my data. I have data for wind speeds, air temperature, pressure and a few other things that depend on position in the X,Y and Z directions. I’ve been using ScatteredInterpolation to interpolate across 1425 data points and then using the interpolant find the wind speeds, air temperature, pressure etc. at a specific position. I was wondering if there was a faster way to do this, either speeding up scatteredinterpolation or a different interpolating method. Am fairly new to MATLAB so help appreciated.
Thanks.Hi,
I’ve been working on speeding up my code for a project and I’ve identified that I’m spending a lot of time interpolating my data. I have data for wind speeds, air temperature, pressure and a few other things that depend on position in the X,Y and Z directions. I’ve been using ScatteredInterpolation to interpolate across 1425 data points and then using the interpolant find the wind speeds, air temperature, pressure etc. at a specific position. I was wondering if there was a faster way to do this, either speeding up scatteredinterpolation or a different interpolating method. Am fairly new to MATLAB so help appreciated.
Thanks. Hi,
I’ve been working on speeding up my code for a project and I’ve identified that I’m spending a lot of time interpolating my data. I have data for wind speeds, air temperature, pressure and a few other things that depend on position in the X,Y and Z directions. I’ve been using ScatteredInterpolation to interpolate across 1425 data points and then using the interpolant find the wind speeds, air temperature, pressure etc. at a specific position. I was wondering if there was a faster way to do this, either speeding up scatteredinterpolation or a different interpolating method. Am fairly new to MATLAB so help appreciated.
Thanks. interpolation MATLAB Answers — New Questions
How to use a global variable when using ode45()?
I have a function named "my_carcontrol3" that gets passed the time "tau" in the ode45() function call. My idea was to use a global variable "i" as an index for "timesV", which is vector containing a series of time instants. I want "i" to increment by 1 when "tau" hits "timesV(i)." So in the my_carcontrol3(), for 0<t<100, i=1. Once "t" hits 100, it increments by 1. And for 100<t<460, i=2. And when "t" hits 460, it increments again and so on. But for whatever reason, the if conditional statement never got triggered in my_carcontrol3().
This is my main function:
z0 = [ 0 0 0];
t0 = 0;
tf = 1000;
timesV=[100,460,720];
global i;
i=1;
[ t1, y1 ] = ode45( @(tau, y1 ) my_carmodel3( tau, y1, @( tau ) my_carcontrol3( tau,timesV,y1(2))), [ t0 tf ], z0 );
This is my_carcontrol3():
function [ control ] = my_carcontrol3( t,timesV,v)
global i;
if t==timesV(i)
i=i+1;
end
control=1
my_carmodel3():
function dydt = my_carmodel3 (t, y, control)
m=1400;
dydt = zeros( 3, 1 );
c = control( t );
dydt( 1 ) = y( 2 );
dydt( 2 ) = c/m;I have a function named "my_carcontrol3" that gets passed the time "tau" in the ode45() function call. My idea was to use a global variable "i" as an index for "timesV", which is vector containing a series of time instants. I want "i" to increment by 1 when "tau" hits "timesV(i)." So in the my_carcontrol3(), for 0<t<100, i=1. Once "t" hits 100, it increments by 1. And for 100<t<460, i=2. And when "t" hits 460, it increments again and so on. But for whatever reason, the if conditional statement never got triggered in my_carcontrol3().
This is my main function:
z0 = [ 0 0 0];
t0 = 0;
tf = 1000;
timesV=[100,460,720];
global i;
i=1;
[ t1, y1 ] = ode45( @(tau, y1 ) my_carmodel3( tau, y1, @( tau ) my_carcontrol3( tau,timesV,y1(2))), [ t0 tf ], z0 );
This is my_carcontrol3():
function [ control ] = my_carcontrol3( t,timesV,v)
global i;
if t==timesV(i)
i=i+1;
end
control=1
my_carmodel3():
function dydt = my_carmodel3 (t, y, control)
m=1400;
dydt = zeros( 3, 1 );
c = control( t );
dydt( 1 ) = y( 2 );
dydt( 2 ) = c/m; I have a function named "my_carcontrol3" that gets passed the time "tau" in the ode45() function call. My idea was to use a global variable "i" as an index for "timesV", which is vector containing a series of time instants. I want "i" to increment by 1 when "tau" hits "timesV(i)." So in the my_carcontrol3(), for 0<t<100, i=1. Once "t" hits 100, it increments by 1. And for 100<t<460, i=2. And when "t" hits 460, it increments again and so on. But for whatever reason, the if conditional statement never got triggered in my_carcontrol3().
This is my main function:
z0 = [ 0 0 0];
t0 = 0;
tf = 1000;
timesV=[100,460,720];
global i;
i=1;
[ t1, y1 ] = ode45( @(tau, y1 ) my_carmodel3( tau, y1, @( tau ) my_carcontrol3( tau,timesV,y1(2))), [ t0 tf ], z0 );
This is my_carcontrol3():
function [ control ] = my_carcontrol3( t,timesV,v)
global i;
if t==timesV(i)
i=i+1;
end
control=1
my_carmodel3():
function dydt = my_carmodel3 (t, y, control)
m=1400;
dydt = zeros( 3, 1 );
c = control( t );
dydt( 1 ) = y( 2 );
dydt( 2 ) = c/m; ode45, control, matlab, matlab code MATLAB Answers — New Questions
How easy is it to give a Matlab toolbox as a Christmas present?
Can I buy gift vouchers?Can I buy gift vouchers? Can I buy gift vouchers? gift voucher MATLAB Answers — New Questions
i keep receiving this error message in matlab
I keep receiving this error message in matlab. im trying to write a script for a plane trust problem for school dont know what im doing wrong at this point. any help is welcome. error message "Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns
in the first matrix matches the number of rows in the second matrix. To operate on
each element of the matrix individually, use TIMES (.*) for elementwise
multiplication.
Error in untitled17 (line 78)
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
% Constants
i = 1; % length of horizontal and vertical members
sqrt2i = sqrt(2) * i; % length of inclined members
E = 100e9; % Young’s modulus (Pa)
A = 1e-4; % cross-sectional area (m^2)
i = 0.3; % moment of inertia (m)
% Define external loads
Fx13 = 10000;
Fx14 = 10000;
Fy13 = 0;
Fy14 = 0;
% Load Case A: Fx13 = Fx14 = 10,000 N
FxA = [10000; 0];
FyA = [0; -10000];
% Load Case B: Fy13 = Fy14 = 10,000 N
FxB = [0; -10000];
FyB= [-10000; 0];
% Load Case C: Fx13=10,000 N and Fx14=-10,000 N
FxC= [10000;-10000];
FyC= [-20000;-20000];
% Assemble global stiffness matrix K and global force vector P for each load case
% Initialize matrices/vectors with zeros
K_A=zeros(6);
P_A=zeros(6,1);
K_B=zeros(6);
P_B=zeros(6,1);
K_C=zeros(6);
P_C=zeros(6,1);
% Define local element stiffness matrix k_e and local force vector p_e
k_e=A*E/i*[1 -1;-1 1]
p_e=[sqrt2i/2;i/2]*[Fx13,Fy13]
for e=[3] %(number of elements)
k_ee=k_e;
p_ee=p_e;
if(e==3)%horizontal member
T_x =[1 0 0 -1];
T_y=[0 1 -1 0];
end
if(e==4)%vertical member
T_x =[0 -1 1 0];
T_y=[-1/2 sqrt2i/2 sqrt2i/2 -1/2];
end
% Compute global element stiffness matrix K_e and global element force vector P_e
K_Ae = zeros(6);
p_Ae = zeros(6, 1);
K_Be = zeros(6);
p_Be = zeros(6, 1);
K_Ce = zeros(6);
p_Ce = zeros(6, 1);
size(T_x’)
size(k_ee)
size(T_x)
size(T_y’)
size(k_ee)
size(T_y)
% Transform local stiffness matrix to global coordinates
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
p_Aeg=T_x’*p_ee;
% Add element contributions to the global stiffness matrix and force vector
K_A([3:4],[3:4])=K([3:4],[3:4])+k_Aeg;
P_A([3:4])=P([3:4])+p_Peg;
end
% Solve for displacements using KU=P equation
U_A=KPI keep receiving this error message in matlab. im trying to write a script for a plane trust problem for school dont know what im doing wrong at this point. any help is welcome. error message "Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns
in the first matrix matches the number of rows in the second matrix. To operate on
each element of the matrix individually, use TIMES (.*) for elementwise
multiplication.
Error in untitled17 (line 78)
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
% Constants
i = 1; % length of horizontal and vertical members
sqrt2i = sqrt(2) * i; % length of inclined members
E = 100e9; % Young’s modulus (Pa)
A = 1e-4; % cross-sectional area (m^2)
i = 0.3; % moment of inertia (m)
% Define external loads
Fx13 = 10000;
Fx14 = 10000;
Fy13 = 0;
Fy14 = 0;
% Load Case A: Fx13 = Fx14 = 10,000 N
FxA = [10000; 0];
FyA = [0; -10000];
% Load Case B: Fy13 = Fy14 = 10,000 N
FxB = [0; -10000];
FyB= [-10000; 0];
% Load Case C: Fx13=10,000 N and Fx14=-10,000 N
FxC= [10000;-10000];
FyC= [-20000;-20000];
% Assemble global stiffness matrix K and global force vector P for each load case
% Initialize matrices/vectors with zeros
K_A=zeros(6);
P_A=zeros(6,1);
K_B=zeros(6);
P_B=zeros(6,1);
K_C=zeros(6);
P_C=zeros(6,1);
% Define local element stiffness matrix k_e and local force vector p_e
k_e=A*E/i*[1 -1;-1 1]
p_e=[sqrt2i/2;i/2]*[Fx13,Fy13]
for e=[3] %(number of elements)
k_ee=k_e;
p_ee=p_e;
if(e==3)%horizontal member
T_x =[1 0 0 -1];
T_y=[0 1 -1 0];
end
if(e==4)%vertical member
T_x =[0 -1 1 0];
T_y=[-1/2 sqrt2i/2 sqrt2i/2 -1/2];
end
% Compute global element stiffness matrix K_e and global element force vector P_e
K_Ae = zeros(6);
p_Ae = zeros(6, 1);
K_Be = zeros(6);
p_Be = zeros(6, 1);
K_Ce = zeros(6);
p_Ce = zeros(6, 1);
size(T_x’)
size(k_ee)
size(T_x)
size(T_y’)
size(k_ee)
size(T_y)
% Transform local stiffness matrix to global coordinates
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
p_Aeg=T_x’*p_ee;
% Add element contributions to the global stiffness matrix and force vector
K_A([3:4],[3:4])=K([3:4],[3:4])+k_Aeg;
P_A([3:4])=P([3:4])+p_Peg;
end
% Solve for displacements using KU=P equation
U_A=KP I keep receiving this error message in matlab. im trying to write a script for a plane trust problem for school dont know what im doing wrong at this point. any help is welcome. error message "Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns
in the first matrix matches the number of rows in the second matrix. To operate on
each element of the matrix individually, use TIMES (.*) for elementwise
multiplication.
Error in untitled17 (line 78)
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
% Constants
i = 1; % length of horizontal and vertical members
sqrt2i = sqrt(2) * i; % length of inclined members
E = 100e9; % Young’s modulus (Pa)
A = 1e-4; % cross-sectional area (m^2)
i = 0.3; % moment of inertia (m)
% Define external loads
Fx13 = 10000;
Fx14 = 10000;
Fy13 = 0;
Fy14 = 0;
% Load Case A: Fx13 = Fx14 = 10,000 N
FxA = [10000; 0];
FyA = [0; -10000];
% Load Case B: Fy13 = Fy14 = 10,000 N
FxB = [0; -10000];
FyB= [-10000; 0];
% Load Case C: Fx13=10,000 N and Fx14=-10,000 N
FxC= [10000;-10000];
FyC= [-20000;-20000];
% Assemble global stiffness matrix K and global force vector P for each load case
% Initialize matrices/vectors with zeros
K_A=zeros(6);
P_A=zeros(6,1);
K_B=zeros(6);
P_B=zeros(6,1);
K_C=zeros(6);
P_C=zeros(6,1);
% Define local element stiffness matrix k_e and local force vector p_e
k_e=A*E/i*[1 -1;-1 1]
p_e=[sqrt2i/2;i/2]*[Fx13,Fy13]
for e=[3] %(number of elements)
k_ee=k_e;
p_ee=p_e;
if(e==3)%horizontal member
T_x =[1 0 0 -1];
T_y=[0 1 -1 0];
end
if(e==4)%vertical member
T_x =[0 -1 1 0];
T_y=[-1/2 sqrt2i/2 sqrt2i/2 -1/2];
end
% Compute global element stiffness matrix K_e and global element force vector P_e
K_Ae = zeros(6);
p_Ae = zeros(6, 1);
K_Be = zeros(6);
p_Be = zeros(6, 1);
K_Ce = zeros(6);
p_Ce = zeros(6, 1);
size(T_x’)
size(k_ee)
size(T_x)
size(T_y’)
size(k_ee)
size(T_y)
% Transform local stiffness matrix to global coordinates
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
p_Aeg=T_x’*p_ee;
% Add element contributions to the global stiffness matrix and force vector
K_A([3:4],[3:4])=K([3:4],[3:4])+k_Aeg;
P_A([3:4])=P([3:4])+p_Peg;
end
% Solve for displacements using KU=P equation
U_A=KP 2-d plane truss MATLAB Answers — New Questions
i keep receiving this error message in matlab
I keep receiving this error message in matlab. im trying to write a script for a plane trust problem for school dont know what im doing wrong at this point. any help is welcome. error message "Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns
in the first matrix matches the number of rows in the second matrix. To operate on
each element of the matrix individually, use TIMES (.*) for elementwise
multiplication.
Error in untitled17 (line 78)
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
% Constants
i = 1; % length of horizontal and vertical members
sqrt2i = sqrt(2) * i; % length of inclined members
E = 100e9; % Young’s modulus (Pa)
A = 1e-4; % cross-sectional area (m^2)
i = 0.3; % moment of inertia (m)
% Define external loads
Fx13 = 10000;
Fx14 = 10000;
Fy13 = 0;
Fy14 = 0;
% Load Case A: Fx13 = Fx14 = 10,000 N
FxA = [10000; 0];
FyA = [0; -10000];
% Load Case B: Fy13 = Fy14 = 10,000 N
FxB = [0; -10000];
FyB= [-10000; 0];
% Load Case C: Fx13=10,000 N and Fx14=-10,000 N
FxC= [10000;-10000];
FyC= [-20000;-20000];
% Assemble global stiffness matrix K and global force vector P for each load case
% Initialize matrices/vectors with zeros
K_A=zeros(6);
P_A=zeros(6,1);
K_B=zeros(6);
P_B=zeros(6,1);
K_C=zeros(6);
P_C=zeros(6,1);
% Define local element stiffness matrix k_e and local force vector p_e
k_e=A*E/i*[1 -1;-1 1]
p_e=[sqrt2i/2;i/2]*[Fx13,Fy13]
for e=[3] %(number of elements)
k_ee=k_e;
p_ee=p_e;
if(e==3)%horizontal member
T_x =[1 0 0 -1];
T_y=[0 1 -1 0];
end
if(e==4)%vertical member
T_x =[0 -1 1 0];
T_y=[-1/2 sqrt2i/2 sqrt2i/2 -1/2];
end
% Compute global element stiffness matrix K_e and global element force vector P_e
K_Ae = zeros(6);
p_Ae = zeros(6, 1);
K_Be = zeros(6);
p_Be = zeros(6, 1);
K_Ce = zeros(6);
p_Ce = zeros(6, 1);
size(T_x’)
size(k_ee)
size(T_x)
size(T_y’)
size(k_ee)
size(T_y)
% Transform local stiffness matrix to global coordinates
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
p_Aeg=T_x’*p_ee;
% Add element contributions to the global stiffness matrix and force vector
K_A([3:4],[3:4])=K([3:4],[3:4])+k_Aeg;
P_A([3:4])=P([3:4])+p_Peg;
end
% Solve for displacements using KU=P equation
U_A=KPI keep receiving this error message in matlab. im trying to write a script for a plane trust problem for school dont know what im doing wrong at this point. any help is welcome. error message "Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns
in the first matrix matches the number of rows in the second matrix. To operate on
each element of the matrix individually, use TIMES (.*) for elementwise
multiplication.
Error in untitled17 (line 78)
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
% Constants
i = 1; % length of horizontal and vertical members
sqrt2i = sqrt(2) * i; % length of inclined members
E = 100e9; % Young’s modulus (Pa)
A = 1e-4; % cross-sectional area (m^2)
i = 0.3; % moment of inertia (m)
% Define external loads
Fx13 = 10000;
Fx14 = 10000;
Fy13 = 0;
Fy14 = 0;
% Load Case A: Fx13 = Fx14 = 10,000 N
FxA = [10000; 0];
FyA = [0; -10000];
% Load Case B: Fy13 = Fy14 = 10,000 N
FxB = [0; -10000];
FyB= [-10000; 0];
% Load Case C: Fx13=10,000 N and Fx14=-10,000 N
FxC= [10000;-10000];
FyC= [-20000;-20000];
% Assemble global stiffness matrix K and global force vector P for each load case
% Initialize matrices/vectors with zeros
K_A=zeros(6);
P_A=zeros(6,1);
K_B=zeros(6);
P_B=zeros(6,1);
K_C=zeros(6);
P_C=zeros(6,1);
% Define local element stiffness matrix k_e and local force vector p_e
k_e=A*E/i*[1 -1;-1 1]
p_e=[sqrt2i/2;i/2]*[Fx13,Fy13]
for e=[3] %(number of elements)
k_ee=k_e;
p_ee=p_e;
if(e==3)%horizontal member
T_x =[1 0 0 -1];
T_y=[0 1 -1 0];
end
if(e==4)%vertical member
T_x =[0 -1 1 0];
T_y=[-1/2 sqrt2i/2 sqrt2i/2 -1/2];
end
% Compute global element stiffness matrix K_e and global element force vector P_e
K_Ae = zeros(6);
p_Ae = zeros(6, 1);
K_Be = zeros(6);
p_Be = zeros(6, 1);
K_Ce = zeros(6);
p_Ce = zeros(6, 1);
size(T_x’)
size(k_ee)
size(T_x)
size(T_y’)
size(k_ee)
size(T_y)
% Transform local stiffness matrix to global coordinates
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
p_Aeg=T_x’*p_ee;
% Add element contributions to the global stiffness matrix and force vector
K_A([3:4],[3:4])=K([3:4],[3:4])+k_Aeg;
P_A([3:4])=P([3:4])+p_Peg;
end
% Solve for displacements using KU=P equation
U_A=KP I keep receiving this error message in matlab. im trying to write a script for a plane trust problem for school dont know what im doing wrong at this point. any help is welcome. error message "Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns
in the first matrix matches the number of rows in the second matrix. To operate on
each element of the matrix individually, use TIMES (.*) for elementwise
multiplication.
Error in untitled17 (line 78)
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
% Constants
i = 1; % length of horizontal and vertical members
sqrt2i = sqrt(2) * i; % length of inclined members
E = 100e9; % Young’s modulus (Pa)
A = 1e-4; % cross-sectional area (m^2)
i = 0.3; % moment of inertia (m)
% Define external loads
Fx13 = 10000;
Fx14 = 10000;
Fy13 = 0;
Fy14 = 0;
% Load Case A: Fx13 = Fx14 = 10,000 N
FxA = [10000; 0];
FyA = [0; -10000];
% Load Case B: Fy13 = Fy14 = 10,000 N
FxB = [0; -10000];
FyB= [-10000; 0];
% Load Case C: Fx13=10,000 N and Fx14=-10,000 N
FxC= [10000;-10000];
FyC= [-20000;-20000];
% Assemble global stiffness matrix K and global force vector P for each load case
% Initialize matrices/vectors with zeros
K_A=zeros(6);
P_A=zeros(6,1);
K_B=zeros(6);
P_B=zeros(6,1);
K_C=zeros(6);
P_C=zeros(6,1);
% Define local element stiffness matrix k_e and local force vector p_e
k_e=A*E/i*[1 -1;-1 1]
p_e=[sqrt2i/2;i/2]*[Fx13,Fy13]
for e=[3] %(number of elements)
k_ee=k_e;
p_ee=p_e;
if(e==3)%horizontal member
T_x =[1 0 0 -1];
T_y=[0 1 -1 0];
end
if(e==4)%vertical member
T_x =[0 -1 1 0];
T_y=[-1/2 sqrt2i/2 sqrt2i/2 -1/2];
end
% Compute global element stiffness matrix K_e and global element force vector P_e
K_Ae = zeros(6);
p_Ae = zeros(6, 1);
K_Be = zeros(6);
p_Be = zeros(6, 1);
K_Ce = zeros(6);
p_Ce = zeros(6, 1);
size(T_x’)
size(k_ee)
size(T_x)
size(T_y’)
size(k_ee)
size(T_y)
% Transform local stiffness matrix to global coordinates
k_Aeg=T_x’*k_ee*T_x+T_y’*k_ee*T_y;
p_Aeg=T_x’*p_ee;
% Add element contributions to the global stiffness matrix and force vector
K_A([3:4],[3:4])=K([3:4],[3:4])+k_Aeg;
P_A([3:4])=P([3:4])+p_Peg;
end
% Solve for displacements using KU=P equation
U_A=KP 2-d plane truss MATLAB Answers — New Questions
¿como conseguir el numero de licencia de matlab?
no se como conseguirlono se como conseguirlo no se como conseguirlo license, installation MATLAB Answers — New Questions
Calculation of mortgage interest from the amount of the mortgage, annuity monthly installments and number of years
I am having troubles to find a equation for interst (x) from the mortgage equation:
a=M*(x/1200*(1+x/1200)^(r*12))/((x/1200+1)^(r*12)-1)
x=? (Online equation solvers can’t calculate it)
For Mortage 100,000 (M), interest x=10 and 1 year (r) monthly annuity a = 8,791.59I am having troubles to find a equation for interst (x) from the mortgage equation:
a=M*(x/1200*(1+x/1200)^(r*12))/((x/1200+1)^(r*12)-1)
x=? (Online equation solvers can’t calculate it)
For Mortage 100,000 (M), interest x=10 and 1 year (r) monthly annuity a = 8,791.59 I am having troubles to find a equation for interst (x) from the mortgage equation:
a=M*(x/1200*(1+x/1200)^(r*12))/((x/1200+1)^(r*12)-1)
x=? (Online equation solvers can’t calculate it)
For Mortage 100,000 (M), interest x=10 and 1 year (r) monthly annuity a = 8,791.59 mortgage, interest MATLAB Answers — New Questions
Calculation of mortgage interest from the amount of the mortgage, annuity monthly installments and number of years
I am having troubles to find a equation for interst (x) from the mortgage equation:
a=M*(x/1200*(1+x/1200)^(r*12))/((x/1200+1)^(r*12)-1)
x=? (Online equation solvers can’t calculate it)
For Mortage 100,000 (M), interest x=10 and 1 year (r) monthly annuity a = 8,791.59I am having troubles to find a equation for interst (x) from the mortgage equation:
a=M*(x/1200*(1+x/1200)^(r*12))/((x/1200+1)^(r*12)-1)
x=? (Online equation solvers can’t calculate it)
For Mortage 100,000 (M), interest x=10 and 1 year (r) monthly annuity a = 8,791.59 I am having troubles to find a equation for interst (x) from the mortgage equation:
a=M*(x/1200*(1+x/1200)^(r*12))/((x/1200+1)^(r*12)-1)
x=? (Online equation solvers can’t calculate it)
For Mortage 100,000 (M), interest x=10 and 1 year (r) monthly annuity a = 8,791.59 mortgage, interest MATLAB Answers — New Questions
Error : Unable to use a value of type optim.problemdef.OptimizationVariable as an index.
Hello !
I am working on a problem-based optimization task where I need to assign 4 subtasks to 4 different nodes. My approach involves defining an optimization variable as a vector with integer elements ranging from 1 to 4, each representing the node assigned to a subtask.
Here’s a snippet of my current setup:
numSubtasks = 4;
numNodes = 4;
taskAssignmentVector = optimvar(‘taskAssignmentVector’, numSubtasks, ‘Type’, ‘integer’, ‘LowerBound’, 1, ‘UpperBound’, numSubtasks);
My goal is to reshape this vector into a 4×4 binary assignment matrix within the optimization framework. Each row of this matrix should correspond to a subtask, and each column to a node, with ‘1’ indicating the assignment.
I attempted to implement this by creating a function to generate the assignment matrix based on the vector, but I’m facing challenges in using the optimization variable as an index, leading to errors.
AssignedMatrix = zeros(numSubtasks, numNodes);
for s = 1:numSubtasks
nodeAssigned = taskAssignmentVector(s); % Node assigned for each subtask
AssignedMatrix(s, nodeAssigned) = 1;
end
Could you please advise on the best approach to reshape this vector into a matrix form within the problem-based optimization framework? I am looking for a way to link the task assignments in the vector with a binary matrix that I can use in my objective function and constraints.
Thank you for your assistance!Hello !
I am working on a problem-based optimization task where I need to assign 4 subtasks to 4 different nodes. My approach involves defining an optimization variable as a vector with integer elements ranging from 1 to 4, each representing the node assigned to a subtask.
Here’s a snippet of my current setup:
numSubtasks = 4;
numNodes = 4;
taskAssignmentVector = optimvar(‘taskAssignmentVector’, numSubtasks, ‘Type’, ‘integer’, ‘LowerBound’, 1, ‘UpperBound’, numSubtasks);
My goal is to reshape this vector into a 4×4 binary assignment matrix within the optimization framework. Each row of this matrix should correspond to a subtask, and each column to a node, with ‘1’ indicating the assignment.
I attempted to implement this by creating a function to generate the assignment matrix based on the vector, but I’m facing challenges in using the optimization variable as an index, leading to errors.
AssignedMatrix = zeros(numSubtasks, numNodes);
for s = 1:numSubtasks
nodeAssigned = taskAssignmentVector(s); % Node assigned for each subtask
AssignedMatrix(s, nodeAssigned) = 1;
end
Could you please advise on the best approach to reshape this vector into a matrix form within the problem-based optimization framework? I am looking for a way to link the task assignments in the vector with a binary matrix that I can use in my objective function and constraints.
Thank you for your assistance! Hello !
I am working on a problem-based optimization task where I need to assign 4 subtasks to 4 different nodes. My approach involves defining an optimization variable as a vector with integer elements ranging from 1 to 4, each representing the node assigned to a subtask.
Here’s a snippet of my current setup:
numSubtasks = 4;
numNodes = 4;
taskAssignmentVector = optimvar(‘taskAssignmentVector’, numSubtasks, ‘Type’, ‘integer’, ‘LowerBound’, 1, ‘UpperBound’, numSubtasks);
My goal is to reshape this vector into a 4×4 binary assignment matrix within the optimization framework. Each row of this matrix should correspond to a subtask, and each column to a node, with ‘1’ indicating the assignment.
I attempted to implement this by creating a function to generate the assignment matrix based on the vector, but I’m facing challenges in using the optimization variable as an index, leading to errors.
AssignedMatrix = zeros(numSubtasks, numNodes);
for s = 1:numSubtasks
nodeAssigned = taskAssignmentVector(s); % Node assigned for each subtask
AssignedMatrix(s, nodeAssigned) = 1;
end
Could you please advise on the best approach to reshape this vector into a matrix form within the problem-based optimization framework? I am looking for a way to link the task assignments in the vector with a binary matrix that I can use in my objective function and constraints.
Thank you for your assistance! optimization, solve, error MATLAB Answers — New Questions
Why does abs cause bad matlabfunction evaluation?
If I run
x = sym(‘x’,’real’);
y = sym(‘y’,’real’);
f = abs(((x – 1)^2 + y^2)^(1/2) – 1)^2 + ((x^2 + y^2)^(1/2) – 1)^2;
d2fdx2 = diff(diff(f,x),x);
[eval(subs(subs(d2fdx2,x,1),y,1)) feval(matlabFunction(d2fdx2),1,1)]
Then I see
ans =
1.2929 NaN
If I remove the abs then I get the correct evaluation for both ([1.2929 1.2929]).
I’m wondering why this abs is causing trouble in matlabFunction . (in this minimal example it’s of course easy to remove)If I run
x = sym(‘x’,’real’);
y = sym(‘y’,’real’);
f = abs(((x – 1)^2 + y^2)^(1/2) – 1)^2 + ((x^2 + y^2)^(1/2) – 1)^2;
d2fdx2 = diff(diff(f,x),x);
[eval(subs(subs(d2fdx2,x,1),y,1)) feval(matlabFunction(d2fdx2),1,1)]
Then I see
ans =
1.2929 NaN
If I remove the abs then I get the correct evaluation for both ([1.2929 1.2929]).
I’m wondering why this abs is causing trouble in matlabFunction . (in this minimal example it’s of course easy to remove) If I run
x = sym(‘x’,’real’);
y = sym(‘y’,’real’);
f = abs(((x – 1)^2 + y^2)^(1/2) – 1)^2 + ((x^2 + y^2)^(1/2) – 1)^2;
d2fdx2 = diff(diff(f,x),x);
[eval(subs(subs(d2fdx2,x,1),y,1)) feval(matlabFunction(d2fdx2),1,1)]
Then I see
ans =
1.2929 NaN
If I remove the abs then I get the correct evaluation for both ([1.2929 1.2929]).
I’m wondering why this abs is causing trouble in matlabFunction . (in this minimal example it’s of course easy to remove) symbolic, matlabfunction, diff, abs MATLAB Answers — New Questions
pdf of Poisson binomial distribution in Matlab
Is there a Matlab implementation for the calculation of the pdf for the Poisson-binomial distribution?Is there a Matlab implementation for the calculation of the pdf for the Poisson-binomial distribution? Is there a Matlab implementation for the calculation of the pdf for the Poisson-binomial distribution? poisson binomial MATLAB Answers — New Questions
How can obtain the probability density function for a random discreate set of data and fit a custom distribution function ??
I have random data. I want to calculate the probability density function. I also fit a custom distribution function which is the where gamma is the gamma function of n and n is the distribution parameter and x is the variable.
I attached the data. Can you provide the solution for this ??I have random data. I want to calculate the probability density function. I also fit a custom distribution function which is the where gamma is the gamma function of n and n is the distribution parameter and x is the variable.
I attached the data. Can you provide the solution for this ?? I have random data. I want to calculate the probability density function. I also fit a custom distribution function which is the where gamma is the gamma function of n and n is the distribution parameter and x is the variable.
I attached the data. Can you provide the solution for this ?? custom distribution fit, pdf MATLAB Answers — New Questions
How to plot the graph for the given RK 4th order step method
syms t x
g=(13950-x)/18.75
f=@(t,x) eval(g);
x0=560;
t0=0;
t=15;
h=1;
for c=1:15
k1=h*f(t0,x0);
k2=h*f(t0+(h/2),x0+(k1/2));
k3=h*f(t0+(h/2),x0+(k2/2));
k4=h*f(t0+h,x0+k3);
x=x0+(1/6)*(k1+(2*k2)+(2*k3)+k4);
fprintf(‘x= %0.4f n’,x)
t0=t0+h;
x0=x;
endsyms t x
g=(13950-x)/18.75
f=@(t,x) eval(g);
x0=560;
t0=0;
t=15;
h=1;
for c=1:15
k1=h*f(t0,x0);
k2=h*f(t0+(h/2),x0+(k1/2));
k3=h*f(t0+(h/2),x0+(k2/2));
k4=h*f(t0+h,x0+k3);
x=x0+(1/6)*(k1+(2*k2)+(2*k3)+k4);
fprintf(‘x= %0.4f n’,x)
t0=t0+h;
x0=x;
end syms t x
g=(13950-x)/18.75
f=@(t,x) eval(g);
x0=560;
t0=0;
t=15;
h=1;
for c=1:15
k1=h*f(t0,x0);
k2=h*f(t0+(h/2),x0+(k1/2));
k3=h*f(t0+(h/2),x0+(k2/2));
k4=h*f(t0+h,x0+k3);
x=x0+(1/6)*(k1+(2*k2)+(2*k3)+k4);
fprintf(‘x= %0.4f n’,x)
t0=t0+h;
x0=x;
end #rkmethod, for loop, #plot graph MATLAB Answers — New Questions
Supply partially complete Jacobian for fsolve()
Hello,
I was wondering if I could supply an incomplete Jacobian to matlab fsolve. I am able to analytically solve for the gradients of some of the constraint equation, but there are some elements that are highly nonlinear and nontrivial to find.
Because of this, I was wondering if I could just partially supply the Jacobian and let MATLAB use its own numerical methods for the missing ones?Hello,
I was wondering if I could supply an incomplete Jacobian to matlab fsolve. I am able to analytically solve for the gradients of some of the constraint equation, but there are some elements that are highly nonlinear and nontrivial to find.
Because of this, I was wondering if I could just partially supply the Jacobian and let MATLAB use its own numerical methods for the missing ones? Hello,
I was wondering if I could supply an incomplete Jacobian to matlab fsolve. I am able to analytically solve for the gradients of some of the constraint equation, but there are some elements that are highly nonlinear and nontrivial to find.
Because of this, I was wondering if I could just partially supply the Jacobian and let MATLAB use its own numerical methods for the missing ones? fsolve, jacobian MATLAB Answers — New Questions
Error : Unable to use a value of type optim.problemdef.OptimizationVariable as an index.
Hello !
I am working on a problem-based optimization task where I need to assign 4 subtasks to 4 different nodes. My approach involves defining an optimization variable as a vector with integer elements ranging from 1 to 4, each representing the node assigned to a subtask.
Here’s a snippet of my current setup:
numSubtasks = 4;
numNodes = 4;
taskAssignmentVector = optimvar(‘taskAssignmentVector’, numSubtasks, ‘Type’, ‘integer’, ‘LowerBound’, 1, ‘UpperBound’, numSubtasks);
My goal is to reshape this vector into a 4×4 binary assignment matrix within the optimization framework. Each row of this matrix should correspond to a subtask, and each column to a node, with ‘1’ indicating the assignment.
I attempted to implement this by creating a function to generate the assignment matrix based on the vector, but I’m facing challenges in using the optimization variable as an index, leading to errors.
AssignedMatrix = zeros(numSubtasks, numNodes);
for s = 1:numSubtasks
nodeAssigned = taskAssignmentVector(s); % Node assigned for each subtask
AssignedMatrix(s, nodeAssigned) = 1;
end
Could you please advise on the best approach to reshape this vector into a matrix form within the problem-based optimization framework? I am looking for a way to link the task assignments in the vector with a binary matrix that I can use in my objective function and constraints.
Thank you for your assistance!Hello !
I am working on a problem-based optimization task where I need to assign 4 subtasks to 4 different nodes. My approach involves defining an optimization variable as a vector with integer elements ranging from 1 to 4, each representing the node assigned to a subtask.
Here’s a snippet of my current setup:
numSubtasks = 4;
numNodes = 4;
taskAssignmentVector = optimvar(‘taskAssignmentVector’, numSubtasks, ‘Type’, ‘integer’, ‘LowerBound’, 1, ‘UpperBound’, numSubtasks);
My goal is to reshape this vector into a 4×4 binary assignment matrix within the optimization framework. Each row of this matrix should correspond to a subtask, and each column to a node, with ‘1’ indicating the assignment.
I attempted to implement this by creating a function to generate the assignment matrix based on the vector, but I’m facing challenges in using the optimization variable as an index, leading to errors.
AssignedMatrix = zeros(numSubtasks, numNodes);
for s = 1:numSubtasks
nodeAssigned = taskAssignmentVector(s); % Node assigned for each subtask
AssignedMatrix(s, nodeAssigned) = 1;
end
Could you please advise on the best approach to reshape this vector into a matrix form within the problem-based optimization framework? I am looking for a way to link the task assignments in the vector with a binary matrix that I can use in my objective function and constraints.
Thank you for your assistance! Hello !
I am working on a problem-based optimization task where I need to assign 4 subtasks to 4 different nodes. My approach involves defining an optimization variable as a vector with integer elements ranging from 1 to 4, each representing the node assigned to a subtask.
Here’s a snippet of my current setup:
numSubtasks = 4;
numNodes = 4;
taskAssignmentVector = optimvar(‘taskAssignmentVector’, numSubtasks, ‘Type’, ‘integer’, ‘LowerBound’, 1, ‘UpperBound’, numSubtasks);
My goal is to reshape this vector into a 4×4 binary assignment matrix within the optimization framework. Each row of this matrix should correspond to a subtask, and each column to a node, with ‘1’ indicating the assignment.
I attempted to implement this by creating a function to generate the assignment matrix based on the vector, but I’m facing challenges in using the optimization variable as an index, leading to errors.
AssignedMatrix = zeros(numSubtasks, numNodes);
for s = 1:numSubtasks
nodeAssigned = taskAssignmentVector(s); % Node assigned for each subtask
AssignedMatrix(s, nodeAssigned) = 1;
end
Could you please advise on the best approach to reshape this vector into a matrix form within the problem-based optimization framework? I am looking for a way to link the task assignments in the vector with a binary matrix that I can use in my objective function and constraints.
Thank you for your assistance! optimization, solve, error MATLAB Answers — New Questions
How to fix the problem of fetching the simulink block from the customized library in the matlab app designer using matlab app designer code?
Here, we are running all the codes shown below in the matlab app designer.
Initialy, we have taken a simulink block from the existing matlab library using this code, and it run successfully.
open_system(new_system(‘myModel’));
add_block(‘simulink/Commonly Used Blocks/Constant’,’myModel/Constant’);
set_param(‘myModel/Constant’,’position’,[140,80,180,120]);
But, on applying the same code to select the simulink block from our customized library, it shows the following error.
open_system(new_system(‘myModel’));
add_block(‘simulink/mylib/Constant’,’myModel/Constant’);
set_param(‘myModel/Constant’,’position’,[220,80,260,120]);
So, the command window in matlab shows following error message.
Error using app2/MylibraryButtonPushed
There is no block named ‘simulink/mylib/Constant’
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, … – Show complete stack trace
Error while evaluating Button PrivateButtonPushedFcn.Here, we are running all the codes shown below in the matlab app designer.
Initialy, we have taken a simulink block from the existing matlab library using this code, and it run successfully.
open_system(new_system(‘myModel’));
add_block(‘simulink/Commonly Used Blocks/Constant’,’myModel/Constant’);
set_param(‘myModel/Constant’,’position’,[140,80,180,120]);
But, on applying the same code to select the simulink block from our customized library, it shows the following error.
open_system(new_system(‘myModel’));
add_block(‘simulink/mylib/Constant’,’myModel/Constant’);
set_param(‘myModel/Constant’,’position’,[220,80,260,120]);
So, the command window in matlab shows following error message.
Error using app2/MylibraryButtonPushed
There is no block named ‘simulink/mylib/Constant’
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, … – Show complete stack trace
Error while evaluating Button PrivateButtonPushedFcn. Here, we are running all the codes shown below in the matlab app designer.
Initialy, we have taken a simulink block from the existing matlab library using this code, and it run successfully.
open_system(new_system(‘myModel’));
add_block(‘simulink/Commonly Used Blocks/Constant’,’myModel/Constant’);
set_param(‘myModel/Constant’,’position’,[140,80,180,120]);
But, on applying the same code to select the simulink block from our customized library, it shows the following error.
open_system(new_system(‘myModel’));
add_block(‘simulink/mylib/Constant’,’myModel/Constant’);
set_param(‘myModel/Constant’,’position’,[220,80,260,120]);
So, the command window in matlab shows following error message.
Error using app2/MylibraryButtonPushed
There is no block named ‘simulink/mylib/Constant’
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, … – Show complete stack trace
Error while evaluating Button PrivateButtonPushedFcn. matlab code, matlab, simulink, app designer, matlab gui MATLAB Answers — New Questions
Sum of following elements in array
Is there a faster way to do the following
s = rand(1, 10);
sum_following = zeros(length(s), 1);
for i = 1:length(s)-1
sum_following(i) = sum(s(i+1:end), ‘all’);
end
without doing
sum_following = sum(s,"all") – cumsum(s);
?Is there a faster way to do the following
s = rand(1, 10);
sum_following = zeros(length(s), 1);
for i = 1:length(s)-1
sum_following(i) = sum(s(i+1:end), ‘all’);
end
without doing
sum_following = sum(s,"all") – cumsum(s);
? Is there a faster way to do the following
s = rand(1, 10);
sum_following = zeros(length(s), 1);
for i = 1:length(s)-1
sum_following(i) = sum(s(i+1:end), ‘all’);
end
without doing
sum_following = sum(s,"all") – cumsum(s);
? arrays, sum, cumsum MATLAB Answers — New Questions
CIC decimation output is strange (Output word length and negative fractional length)
I’m implementing fixed point CIC decimation filter with following requirements —
Decimation factor: 20
Number of CIC stages: 4
Input and output bit width of the CIC: Signed 12-bit
Based on the above requirement, I created a CIC filter
cicDecimOut = dsp.CICDecimator(DecimationFactor=20,…
NumSections=4,…
FixedPointDataType="Specify word lengths",…
SectionWordLengths=12,…
OutputWordLength=12);
As an input, 12-bit signed data generated as follow.
x = randi([-2048 2047], 100000, 1);
in = fi(x,1,12);
Now the singned 12-bit input data plug-in to the CIC decimation filter.
out = cicDecimOut(in)
However, checking the out shows the following at the end,
Two questions I have —
I was expecting signed 12-bit output as I set the OutputWordLength=12. However, out is much larger than 12-bit range. Why this happened. Not sure I was missing something. How could I fix this?
FractionLength is a negative value (-18). Can this be 0 as I wanted to see signed 12-bit? How could I compare this out with the values from the real RTL implementation?I’m implementing fixed point CIC decimation filter with following requirements —
Decimation factor: 20
Number of CIC stages: 4
Input and output bit width of the CIC: Signed 12-bit
Based on the above requirement, I created a CIC filter
cicDecimOut = dsp.CICDecimator(DecimationFactor=20,…
NumSections=4,…
FixedPointDataType="Specify word lengths",…
SectionWordLengths=12,…
OutputWordLength=12);
As an input, 12-bit signed data generated as follow.
x = randi([-2048 2047], 100000, 1);
in = fi(x,1,12);
Now the singned 12-bit input data plug-in to the CIC decimation filter.
out = cicDecimOut(in)
However, checking the out shows the following at the end,
Two questions I have —
I was expecting signed 12-bit output as I set the OutputWordLength=12. However, out is much larger than 12-bit range. Why this happened. Not sure I was missing something. How could I fix this?
FractionLength is a negative value (-18). Can this be 0 as I wanted to see signed 12-bit? How could I compare this out with the values from the real RTL implementation? I’m implementing fixed point CIC decimation filter with following requirements —
Decimation factor: 20
Number of CIC stages: 4
Input and output bit width of the CIC: Signed 12-bit
Based on the above requirement, I created a CIC filter
cicDecimOut = dsp.CICDecimator(DecimationFactor=20,…
NumSections=4,…
FixedPointDataType="Specify word lengths",…
SectionWordLengths=12,…
OutputWordLength=12);
As an input, 12-bit signed data generated as follow.
x = randi([-2048 2047], 100000, 1);
in = fi(x,1,12);
Now the singned 12-bit input data plug-in to the CIC decimation filter.
out = cicDecimOut(in)
However, checking the out shows the following at the end,
Two questions I have —
I was expecting signed 12-bit output as I set the OutputWordLength=12. However, out is much larger than 12-bit range. Why this happened. Not sure I was missing something. How could I fix this?
FractionLength is a negative value (-18). Can this be 0 as I wanted to see signed 12-bit? How could I compare this out with the values from the real RTL implementation? cic, output word length, fractional word length, fixed-point MATLAB Answers — New Questions