Tag Archives: matlab
Not enough arguments error in simulink model
Hi, I have created a simple model to process two images to detect features, and output distance estimates between matching features. The model has two spurces from corresponding files, Image 1 and Image 2. Each image is converted to RGB, and input to a function block I have defined as v= functionKAZE(grayImg1, grayImg2). This function block is linked to a scope showing v vs. time.
When I run this model, simulink responds with the error message "Not enough input arguments.". I have checked my function separately with the image files supplied from the command prompt, and works fine. What could I have missed? Thanks In advance.Hi, I have created a simple model to process two images to detect features, and output distance estimates between matching features. The model has two spurces from corresponding files, Image 1 and Image 2. Each image is converted to RGB, and input to a function block I have defined as v= functionKAZE(grayImg1, grayImg2). This function block is linked to a scope showing v vs. time.
When I run this model, simulink responds with the error message "Not enough input arguments.". I have checked my function separately with the image files supplied from the command prompt, and works fine. What could I have missed? Thanks In advance. Hi, I have created a simple model to process two images to detect features, and output distance estimates between matching features. The model has two spurces from corresponding files, Image 1 and Image 2. Each image is converted to RGB, and input to a function block I have defined as v= functionKAZE(grayImg1, grayImg2). This function block is linked to a scope showing v vs. time.
When I run this model, simulink responds with the error message "Not enough input arguments.". I have checked my function separately with the image files supplied from the command prompt, and works fine. What could I have missed? Thanks In advance. simulink, user function, model error MATLAB Answers — New Questions
Exportgraphics is not overwriting
I have a set of figures that I’m saving using exportgraphics, after making some changes to the programm i get a new set of figures but exportgraphics is not overwriting it. I have been using this to export images for a long time and it used to overwrite, but since yesterday it isn’t doing so. Any ideas about what may be causing this?I have a set of figures that I’m saving using exportgraphics, after making some changes to the programm i get a new set of figures but exportgraphics is not overwriting it. I have been using this to export images for a long time and it used to overwrite, but since yesterday it isn’t doing so. Any ideas about what may be causing this? I have a set of figures that I’m saving using exportgraphics, after making some changes to the programm i get a new set of figures but exportgraphics is not overwriting it. I have been using this to export images for a long time and it used to overwrite, but since yesterday it isn’t doing so. Any ideas about what may be causing this? export, image, save MATLAB Answers — New Questions
How to get acceleration data while using ODE solver for some governing equation of motion?
I am using ODE solver for a system of equations governing the motion of a model. In fact I am integrating the acceleration expressions by using ODE solver after converting them into state space form. and the Output I can get is position and velocities. How can I get the corresponding acceleration data? As the acceleration is alraedy definded in the form of expression in dydt vector, can’t I store the value of thethis vector which can give the acceleration? Please suggest me any simpler way to get acceleration without using any numerical approach to calculate acceleration from velocity data or finding the 3rd order diff. equation and then integrate to get acceleration.I am using ODE solver for a system of equations governing the motion of a model. In fact I am integrating the acceleration expressions by using ODE solver after converting them into state space form. and the Output I can get is position and velocities. How can I get the corresponding acceleration data? As the acceleration is alraedy definded in the form of expression in dydt vector, can’t I store the value of thethis vector which can give the acceleration? Please suggest me any simpler way to get acceleration without using any numerical approach to calculate acceleration from velocity data or finding the 3rd order diff. equation and then integrate to get acceleration. I am using ODE solver for a system of equations governing the motion of a model. In fact I am integrating the acceleration expressions by using ODE solver after converting them into state space form. and the Output I can get is position and velocities. How can I get the corresponding acceleration data? As the acceleration is alraedy definded in the form of expression in dydt vector, can’t I store the value of thethis vector which can give the acceleration? Please suggest me any simpler way to get acceleration without using any numerical approach to calculate acceleration from velocity data or finding the 3rd order diff. equation and then integrate to get acceleration. ode45 MATLAB Answers — New Questions
MCC USB-231 DAQ Digital I/O
Can the USB-231 DAQ handle digital input/output? In Matlab, I am doing an addinput() but it is saying digital is not supported.Can the USB-231 DAQ handle digital input/output? In Matlab, I am doing an addinput() but it is saying digital is not supported. Can the USB-231 DAQ handle digital input/output? In Matlab, I am doing an addinput() but it is saying digital is not supported. matlab, data acquisition, mcc MATLAB Answers — New Questions
How to add an NVCC flag
I am attempting to compile a program using CUDA, and am getting the following error in response
C:Program FilesMATLABR2024asyscudawin64cudaincludecrt/host_config.h(164): fatal error C1189:
#error: — unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022
(inclusive) are supported! The nvcc flag ‘-allow-unsupported-compiler’ can be used to override this
version check; however, using an unsupported host compiler may cause compilation failure or incorrect run
time execution. Use at your own risk.
I looked and it seems the problem is caused by a small glitch in a recent update of visual studio that shouldnt have any effect on the compiler. How do I add the flag to override the version check? My current code is as follows
mex -setup:’C:Program FilesMATLABR2024abinwin64mexoptsmsvcpp2022.xml’ C++
mexGPUallI am attempting to compile a program using CUDA, and am getting the following error in response
C:Program FilesMATLABR2024asyscudawin64cudaincludecrt/host_config.h(164): fatal error C1189:
#error: — unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022
(inclusive) are supported! The nvcc flag ‘-allow-unsupported-compiler’ can be used to override this
version check; however, using an unsupported host compiler may cause compilation failure or incorrect run
time execution. Use at your own risk.
I looked and it seems the problem is caused by a small glitch in a recent update of visual studio that shouldnt have any effect on the compiler. How do I add the flag to override the version check? My current code is as follows
mex -setup:’C:Program FilesMATLABR2024abinwin64mexoptsmsvcpp2022.xml’ C++
mexGPUall I am attempting to compile a program using CUDA, and am getting the following error in response
C:Program FilesMATLABR2024asyscudawin64cudaincludecrt/host_config.h(164): fatal error C1189:
#error: — unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022
(inclusive) are supported! The nvcc flag ‘-allow-unsupported-compiler’ can be used to override this
version check; however, using an unsupported host compiler may cause compilation failure or incorrect run
time execution. Use at your own risk.
I looked and it seems the problem is caused by a small glitch in a recent update of visual studio that shouldnt have any effect on the compiler. How do I add the flag to override the version check? My current code is as follows
mex -setup:’C:Program FilesMATLABR2024abinwin64mexoptsmsvcpp2022.xml’ C++
mexGPUall mex, compiler MATLAB Answers — New Questions
Solver decreases step-size at certain anomalies
Hey hello there!
So i have the following Issue. I am simulating the attitude (orientation) of a satellite via simulink. My initial conditions are usually a spinning satellite that gets slowed down. And when i reach small turn rates (derivative of the magnetic field is very low) my simulation breaks down and my step size decreases so drastically that it takes almost 30min to simulate 1s. And that cant be right somehow.
My tolerance settings are:
Absolute Tolerance: 10*e-8
Relative Tolerance: 10*e-6
Maybe they are low, but they work for most of the time with reasonable step sizes. (as one can see in the graph below)
This is how the step-size graph looks like for an edge case where i get the solver exceptiosn with error control but only for "short" time frames that still take minutes to compute.
At those time intervals the derivative of the magnetic field approaches 0 (1st graph below) and starts to do weird stuff. But when i tell the derivative that it should be 0 when close to 0 the simulation slows down even faster and my magnetic field derivative just starts to flicker (2nd graph).
Are there any general things one has to consider? Does stuff like this happen often in simulations?
Any Ideas how to fix this?
Some more additional Information:
Simulation Overview:
So what the simulation basically does is. It tries to bring the angular velocity of the satellite close to zero. This is done by "measuring" the magnetic field of earth and then trying to align the satellite with earths magnetic field (as it can be roughly assumed constant). This is done via this logic:
Here the graph of my angular Velocity around the x-Axis and the Angular Acceleration Graph when those anomalies occur:
(The Angular acceleration graph is zoomed in on the y-axis as otherwise one would only see the spikes and the angular velocity graph is zoomed in a lot in both axis)
One can clearly see that the Angular Velocity first runs smoothly and then for some reason flattens out until increasing not so smoothly.
If you need more information i will gladly provide them.
Thanks for your Help :)Hey hello there!
So i have the following Issue. I am simulating the attitude (orientation) of a satellite via simulink. My initial conditions are usually a spinning satellite that gets slowed down. And when i reach small turn rates (derivative of the magnetic field is very low) my simulation breaks down and my step size decreases so drastically that it takes almost 30min to simulate 1s. And that cant be right somehow.
My tolerance settings are:
Absolute Tolerance: 10*e-8
Relative Tolerance: 10*e-6
Maybe they are low, but they work for most of the time with reasonable step sizes. (as one can see in the graph below)
This is how the step-size graph looks like for an edge case where i get the solver exceptiosn with error control but only for "short" time frames that still take minutes to compute.
At those time intervals the derivative of the magnetic field approaches 0 (1st graph below) and starts to do weird stuff. But when i tell the derivative that it should be 0 when close to 0 the simulation slows down even faster and my magnetic field derivative just starts to flicker (2nd graph).
Are there any general things one has to consider? Does stuff like this happen often in simulations?
Any Ideas how to fix this?
Some more additional Information:
Simulation Overview:
So what the simulation basically does is. It tries to bring the angular velocity of the satellite close to zero. This is done by "measuring" the magnetic field of earth and then trying to align the satellite with earths magnetic field (as it can be roughly assumed constant). This is done via this logic:
Here the graph of my angular Velocity around the x-Axis and the Angular Acceleration Graph when those anomalies occur:
(The Angular acceleration graph is zoomed in on the y-axis as otherwise one would only see the spikes and the angular velocity graph is zoomed in a lot in both axis)
One can clearly see that the Angular Velocity first runs smoothly and then for some reason flattens out until increasing not so smoothly.
If you need more information i will gladly provide them.
Thanks for your Help 🙂 Hey hello there!
So i have the following Issue. I am simulating the attitude (orientation) of a satellite via simulink. My initial conditions are usually a spinning satellite that gets slowed down. And when i reach small turn rates (derivative of the magnetic field is very low) my simulation breaks down and my step size decreases so drastically that it takes almost 30min to simulate 1s. And that cant be right somehow.
My tolerance settings are:
Absolute Tolerance: 10*e-8
Relative Tolerance: 10*e-6
Maybe they are low, but they work for most of the time with reasonable step sizes. (as one can see in the graph below)
This is how the step-size graph looks like for an edge case where i get the solver exceptiosn with error control but only for "short" time frames that still take minutes to compute.
At those time intervals the derivative of the magnetic field approaches 0 (1st graph below) and starts to do weird stuff. But when i tell the derivative that it should be 0 when close to 0 the simulation slows down even faster and my magnetic field derivative just starts to flicker (2nd graph).
Are there any general things one has to consider? Does stuff like this happen often in simulations?
Any Ideas how to fix this?
Some more additional Information:
Simulation Overview:
So what the simulation basically does is. It tries to bring the angular velocity of the satellite close to zero. This is done by "measuring" the magnetic field of earth and then trying to align the satellite with earths magnetic field (as it can be roughly assumed constant). This is done via this logic:
Here the graph of my angular Velocity around the x-Axis and the Angular Acceleration Graph when those anomalies occur:
(The Angular acceleration graph is zoomed in on the y-axis as otherwise one would only see the spikes and the angular velocity graph is zoomed in a lot in both axis)
One can clearly see that the Angular Velocity first runs smoothly and then for some reason flattens out until increasing not so smoothly.
If you need more information i will gladly provide them.
Thanks for your Help 🙂 simulink, solver, step-size MATLAB Answers — New Questions
how to write a function for quadratic equation
I wrote this into matlab but it doesn’t work, can someone explain why?
function [x1,x2] = QuadraticEquation (a,b,c)
d=b^2-4*a*c;
if d>=0
disp (‘two roots exist’)
x1=(-b-sqrt(d))/2*a
x2=(-b+sqrt(d))/2*a
plot(x1,0,’rx’,x2,0,’rx’)
hold on
x=-10:10
y=a*x.^2+b*x+c
plot(x,y)
hold off
else
disp (‘no real roots’)
endI wrote this into matlab but it doesn’t work, can someone explain why?
function [x1,x2] = QuadraticEquation (a,b,c)
d=b^2-4*a*c;
if d>=0
disp (‘two roots exist’)
x1=(-b-sqrt(d))/2*a
x2=(-b+sqrt(d))/2*a
plot(x1,0,’rx’,x2,0,’rx’)
hold on
x=-10:10
y=a*x.^2+b*x+c
plot(x,y)
hold off
else
disp (‘no real roots’)
end I wrote this into matlab but it doesn’t work, can someone explain why?
function [x1,x2] = QuadraticEquation (a,b,c)
d=b^2-4*a*c;
if d>=0
disp (‘two roots exist’)
x1=(-b-sqrt(d))/2*a
x2=(-b+sqrt(d))/2*a
plot(x1,0,’rx’,x2,0,’rx’)
hold on
x=-10:10
y=a*x.^2+b*x+c
plot(x,y)
hold off
else
disp (‘no real roots’)
end matlab, quadratic equation MATLAB Answers — New Questions
UPFC modelling and running of simulation
hello, i found a model regarding UPFC detailed model and i went throught the article written regarding the simulation and i refered back to the model but i do not understand the scope can someone explain them to me please.hello, i found a model regarding UPFC detailed model and i went throught the article written regarding the simulation and i refered back to the model but i do not understand the scope can someone explain them to me please. hello, i found a model regarding UPFC detailed model and i went throught the article written regarding the simulation and i refered back to the model but i do not understand the scope can someone explain them to me please. matlab, simulink, power_electronics_control MATLAB Answers — New Questions
Error using urROS2Node
Hi,
I am using MATLAB 2024a in linux, where I have installed ROS 2 and Dependencies as proposed in here by using the automated method.
As can be seen in the picture, evrething seems to work fine.
However, I am trying to connect to the UR simulator, as explained in this example using this script:
clear, clc;
ur5e = loadrobot(‘universalUR5e’);
username = ‘xxxxxx’;
password = ‘xxxxxxx’;
ROS2Folder = ‘/opt/ros/humble’;
ROS2Workspace = ‘/opt/ros/humble’; % In case of binary installation, ROS 2 Work-space is same as ROS 2 Folder
ROS2DeviceAddress = ‘192.168.56.1’;
robotAddress = ‘192.168.56.101’;
device = ros2device(ROS2DeviceAddress,username,password);
device.ROS2Folder = ROS2Folder;
device.ROS2Workspace = ROS2Workspace;
generateAndTransferLaunchScriptROS2GettingStarted(device,ROS2Workspace,robotAddress);
pause(10)
ur = urROS2Node(‘RigidBodyTree’,ur5e);
and modifying the associated function so it works on simulation:
function generateAndTransferLaunchScriptROS2GettingStarted(device,WorkSpaceFolder,RobotAddress)
% Open a file to write set of commands to launch simulated UR5e
% in URSim
fid=fopen(fullfile(tempdir,"launchUR5eROS2.sh"),"w+");
% launch depending on the installation of ros2 ur driver
if strcmp(WorkSpaceFolder, device.ROS2Folder)
% Launch command for binary installation
fprintf(fid,"gnome-terminal –title=42Simulated UR5e Robot42 — /bin/bash -c ‘source %s/setup.bash; ros2 launch ur_robot_driver ur5e.launch.py launch_rviz:=false robot_ip:=%s’",device.ROS2Folder,RobotAddress);
else
% Launch command for source installation
fprintf(fid,"gnome-terminal –title=42Simulated UR5e Robot42 — /bin/bash -c ‘source %s/setup.bash; source %s/install/setup.bash; ros2 launch ur_robot_driver ur5e.launch.py launch_rviz:=false robot_ip:=%s’",device.ROS2Folder,WorkSpaceFolder,RobotAddress);
end
fclose(fid);
% Copy file into ROS2 device
putFile(device,fullfile(tempdir,’launchUR5eROS2.sh’),’~/’)
% Make the shell script executable
system(device,’chmod a+x ~/launchUR5eROS2.sh’);
% Launch the script
% system(device,’./launchUR5eROS2HWSetup.sh &’);
system(device,’./launchUR5eROS2.sh &’); % JL: I use this instead
end
The UR sim loger viewer indicates that the communication is reached.
However, I am getting this error:
Error using ros.internal.getEmptyMessage>getMessageDataAndInfo (line 70)
How could I solve it so I can continue with the example execution?
Screenshot of the Matlab and urSim windows:Hi,
I am using MATLAB 2024a in linux, where I have installed ROS 2 and Dependencies as proposed in here by using the automated method.
As can be seen in the picture, evrething seems to work fine.
However, I am trying to connect to the UR simulator, as explained in this example using this script:
clear, clc;
ur5e = loadrobot(‘universalUR5e’);
username = ‘xxxxxx’;
password = ‘xxxxxxx’;
ROS2Folder = ‘/opt/ros/humble’;
ROS2Workspace = ‘/opt/ros/humble’; % In case of binary installation, ROS 2 Work-space is same as ROS 2 Folder
ROS2DeviceAddress = ‘192.168.56.1’;
robotAddress = ‘192.168.56.101’;
device = ros2device(ROS2DeviceAddress,username,password);
device.ROS2Folder = ROS2Folder;
device.ROS2Workspace = ROS2Workspace;
generateAndTransferLaunchScriptROS2GettingStarted(device,ROS2Workspace,robotAddress);
pause(10)
ur = urROS2Node(‘RigidBodyTree’,ur5e);
and modifying the associated function so it works on simulation:
function generateAndTransferLaunchScriptROS2GettingStarted(device,WorkSpaceFolder,RobotAddress)
% Open a file to write set of commands to launch simulated UR5e
% in URSim
fid=fopen(fullfile(tempdir,"launchUR5eROS2.sh"),"w+");
% launch depending on the installation of ros2 ur driver
if strcmp(WorkSpaceFolder, device.ROS2Folder)
% Launch command for binary installation
fprintf(fid,"gnome-terminal –title=42Simulated UR5e Robot42 — /bin/bash -c ‘source %s/setup.bash; ros2 launch ur_robot_driver ur5e.launch.py launch_rviz:=false robot_ip:=%s’",device.ROS2Folder,RobotAddress);
else
% Launch command for source installation
fprintf(fid,"gnome-terminal –title=42Simulated UR5e Robot42 — /bin/bash -c ‘source %s/setup.bash; source %s/install/setup.bash; ros2 launch ur_robot_driver ur5e.launch.py launch_rviz:=false robot_ip:=%s’",device.ROS2Folder,WorkSpaceFolder,RobotAddress);
end
fclose(fid);
% Copy file into ROS2 device
putFile(device,fullfile(tempdir,’launchUR5eROS2.sh’),’~/’)
% Make the shell script executable
system(device,’chmod a+x ~/launchUR5eROS2.sh’);
% Launch the script
% system(device,’./launchUR5eROS2HWSetup.sh &’);
system(device,’./launchUR5eROS2.sh &’); % JL: I use this instead
end
The UR sim loger viewer indicates that the communication is reached.
However, I am getting this error:
Error using ros.internal.getEmptyMessage>getMessageDataAndInfo (line 70)
How could I solve it so I can continue with the example execution?
Screenshot of the Matlab and urSim windows: Hi,
I am using MATLAB 2024a in linux, where I have installed ROS 2 and Dependencies as proposed in here by using the automated method.
As can be seen in the picture, evrething seems to work fine.
However, I am trying to connect to the UR simulator, as explained in this example using this script:
clear, clc;
ur5e = loadrobot(‘universalUR5e’);
username = ‘xxxxxx’;
password = ‘xxxxxxx’;
ROS2Folder = ‘/opt/ros/humble’;
ROS2Workspace = ‘/opt/ros/humble’; % In case of binary installation, ROS 2 Work-space is same as ROS 2 Folder
ROS2DeviceAddress = ‘192.168.56.1’;
robotAddress = ‘192.168.56.101’;
device = ros2device(ROS2DeviceAddress,username,password);
device.ROS2Folder = ROS2Folder;
device.ROS2Workspace = ROS2Workspace;
generateAndTransferLaunchScriptROS2GettingStarted(device,ROS2Workspace,robotAddress);
pause(10)
ur = urROS2Node(‘RigidBodyTree’,ur5e);
and modifying the associated function so it works on simulation:
function generateAndTransferLaunchScriptROS2GettingStarted(device,WorkSpaceFolder,RobotAddress)
% Open a file to write set of commands to launch simulated UR5e
% in URSim
fid=fopen(fullfile(tempdir,"launchUR5eROS2.sh"),"w+");
% launch depending on the installation of ros2 ur driver
if strcmp(WorkSpaceFolder, device.ROS2Folder)
% Launch command for binary installation
fprintf(fid,"gnome-terminal –title=42Simulated UR5e Robot42 — /bin/bash -c ‘source %s/setup.bash; ros2 launch ur_robot_driver ur5e.launch.py launch_rviz:=false robot_ip:=%s’",device.ROS2Folder,RobotAddress);
else
% Launch command for source installation
fprintf(fid,"gnome-terminal –title=42Simulated UR5e Robot42 — /bin/bash -c ‘source %s/setup.bash; source %s/install/setup.bash; ros2 launch ur_robot_driver ur5e.launch.py launch_rviz:=false robot_ip:=%s’",device.ROS2Folder,WorkSpaceFolder,RobotAddress);
end
fclose(fid);
% Copy file into ROS2 device
putFile(device,fullfile(tempdir,’launchUR5eROS2.sh’),’~/’)
% Make the shell script executable
system(device,’chmod a+x ~/launchUR5eROS2.sh’);
% Launch the script
% system(device,’./launchUR5eROS2HWSetup.sh &’);
system(device,’./launchUR5eROS2.sh &’); % JL: I use this instead
end
The UR sim loger viewer indicates that the communication is reached.
However, I am getting this error:
Error using ros.internal.getEmptyMessage>getMessageDataAndInfo (line 70)
How could I solve it so I can continue with the example execution?
Screenshot of the Matlab and urSim windows: urros2node, ur robot, ros2 MATLAB Answers — New Questions
Using the Black/Scholes Option Pricing Model, calculate the value of the call option given: S= 70; X=80; T=3 months; =.49; Rf =10%
Using the Black/Scholes Option Pricing Model, calculate the value of the call option given:
S= 70; X=80; T=3 months; s2=.49; Rf =10%Using the Black/Scholes Option Pricing Model, calculate the value of the call option given:
S= 70; X=80; T=3 months; s2=.49; Rf =10% Using the Black/Scholes Option Pricing Model, calculate the value of the call option given:
S= 70; X=80; T=3 months; s2=.49; Rf =10% mba MATLAB Answers — New Questions
indicating regions of flutter (F), and divergence (D)
I tried to implemented the stability boundries of a 2DOF system while my coefficents are periodic.
Initially, I wrote my homogeneous matrix and directly examined the eigenvalues, but the final plot didn’t match the reference.
clc
clear all ;
% Define parameters
I_thetaoverI_b = 2 ; % Moment of inertia pitch axis over I_b
I_psioverI_b = 2 ; % Moment of inertia yaw axis over I_b
C_thetaoverI_b = 0.00; % Damping coefficient over I_b
C_psioverI_b = 0.00; % Damping coefficient over I_b
h = 0.3; % rotor mast height
hoverR = 0.34;
R = h / hoverR;
gamma = 4; % lock number
V = 325 ; % the rotor forward velocity [knots]
Omega = V/R; % the rotor rotational speed [RPM]
freq_1_over_Omega = 1 / Omega;
%the flap moment aerodynamic coefficients for large V
M_b = -(1/10)*V;
M_u = 1/6;
%the propeller aerodynamic coefficients
H_u = V/2;
%%%%%%%%%%%the flap moment aerodynamic coefficients for small V
%M_b = -1*(1 + V^2)/8 ;
%M_u = V/4;
%the propeller aerodynamic coefficients
%H_u = (V^2/2)*log(2/V);
f_pitch= 0.01:5:140;
f_yaw= 0.01:5:140;
phi_steps = linspace(0, pi, 50); % Evaluation points from 0 to pi
divergence_map = [];
Rdivergence_map = [];
unstable = [];
for i = 1:length(f_pitch)
for j = 1:length(f_yaw)
for phi = phi_steps
% Calculate stiffness for the current frequency
w_omega_pitch = 2*pi*f_pitch(i);
w_omega_yaw = 2*pi*f_yaw(j);
K_psi = (w_omega_pitch^2) * I_psioverI_b;
K_theta = (w_omega_yaw^2) * I_thetaoverI_b;
% Define inertia matrix [M]
M_matrix = [I_thetaoverI_b + 1 + cos(2*phi), -sin(2*phi);
-sin(2*phi), I_psioverI_b + 1 – cos(2*phi)];
% Define damping matrix [D]
D11 = h^2*gamma*H_u*(1 – cos(2*phi)) – gamma*M_b*(1 + cos(2*phi)) – (2 + 2*h*gamma*M_u)*sin(2*phi);
D12 = h^2*gamma*H_u*sin(2*phi) + gamma*M_b*sin(2*phi) – 2*(1 + cos(2*phi)) – 2*h*gamma*M_u*cos(2*phi);
D21 = h^2*gamma*H_u*sin(2*phi) + gamma*M_b*sin(2*phi) + 2*(1 – cos(2*phi)) – 2*h*gamma*M_u*cos(2*phi);
D22 = h^2*gamma*H_u*(1 + cos(2*phi)) – gamma*M_b*(1 – cos(2*phi)) + (2 + 2*h*gamma*M_u)*sin(2*phi);
D_matrix = [D11, D12;
D21, D22];
% Define stiffness matrix [K]
K11 = K_theta – h*gamma*V*H_u*(1 – cos(2*phi)) + gamma*V*M_u*sin(2*phi);
K12 = -h*V*gamma*H_u*sin(2*phi) + gamma*V*M_u*(1 + cos(2*phi));
K21 = -h*gamma*V*H_u*sin(2*phi) – gamma*V*M_u*(1 – cos(2*phi));
K22 = K_psi – h*gamma*V*H_u*(1 + cos(2*phi)) – gamma*V*M_u*sin(2*phi);
K_matrix = [K11, K12;
K21, K22];
A_top = [zeros(2, 2), eye(2)];
A_bottom = [-inv(M_matrix) * K_matrix, -inv(M_matrix) * D_matrix];
A = [A_top; A_bottom];
eigenvalues = eig(A);
% Stability condition
% Flutter
if any(real(eigenvalues) > 0)
unstable = [unstable; K_psi, K_theta];
end
% Divergence condition
if det(K_matrix) < 0
divergence_map = [divergence_map; K_psi, K_theta];
end
% 1/Ω *(Divergence) proximity check
for ev = eigenvalues’
if abs(ev – freq_1_over_Omega) < 1e-2
Rdivergence_map = [Rdivergence_map; K_psi, K_theta];
end
end
end
end
end
% Plot the Flutter and divergence maps
figure;
hold on;
scatter(unstable(:,1), unstable(:,2), ‘filled’);
scatter(divergence_map(:,1), divergence_map(:,2), ‘filled’, ‘r’);
scatter(Rdivergence_map(:, 1), Rdivergence_map(:, 2), ‘filled’, ‘g’);
xlabel(‘K_psi’);
ylabel(‘K_theta’);
title(‘Whirl Flutter Diagram’);
legend(‘Flutter area’, ‘Divergence area’, ‘ 1/Ω Divergence area’);
hold off;
I’d appreciate it if you could check it. Also, if I need to use the Floquet technique, please let me know how to modify the code.I tried to implemented the stability boundries of a 2DOF system while my coefficents are periodic.
Initially, I wrote my homogeneous matrix and directly examined the eigenvalues, but the final plot didn’t match the reference.
clc
clear all ;
% Define parameters
I_thetaoverI_b = 2 ; % Moment of inertia pitch axis over I_b
I_psioverI_b = 2 ; % Moment of inertia yaw axis over I_b
C_thetaoverI_b = 0.00; % Damping coefficient over I_b
C_psioverI_b = 0.00; % Damping coefficient over I_b
h = 0.3; % rotor mast height
hoverR = 0.34;
R = h / hoverR;
gamma = 4; % lock number
V = 325 ; % the rotor forward velocity [knots]
Omega = V/R; % the rotor rotational speed [RPM]
freq_1_over_Omega = 1 / Omega;
%the flap moment aerodynamic coefficients for large V
M_b = -(1/10)*V;
M_u = 1/6;
%the propeller aerodynamic coefficients
H_u = V/2;
%%%%%%%%%%%the flap moment aerodynamic coefficients for small V
%M_b = -1*(1 + V^2)/8 ;
%M_u = V/4;
%the propeller aerodynamic coefficients
%H_u = (V^2/2)*log(2/V);
f_pitch= 0.01:5:140;
f_yaw= 0.01:5:140;
phi_steps = linspace(0, pi, 50); % Evaluation points from 0 to pi
divergence_map = [];
Rdivergence_map = [];
unstable = [];
for i = 1:length(f_pitch)
for j = 1:length(f_yaw)
for phi = phi_steps
% Calculate stiffness for the current frequency
w_omega_pitch = 2*pi*f_pitch(i);
w_omega_yaw = 2*pi*f_yaw(j);
K_psi = (w_omega_pitch^2) * I_psioverI_b;
K_theta = (w_omega_yaw^2) * I_thetaoverI_b;
% Define inertia matrix [M]
M_matrix = [I_thetaoverI_b + 1 + cos(2*phi), -sin(2*phi);
-sin(2*phi), I_psioverI_b + 1 – cos(2*phi)];
% Define damping matrix [D]
D11 = h^2*gamma*H_u*(1 – cos(2*phi)) – gamma*M_b*(1 + cos(2*phi)) – (2 + 2*h*gamma*M_u)*sin(2*phi);
D12 = h^2*gamma*H_u*sin(2*phi) + gamma*M_b*sin(2*phi) – 2*(1 + cos(2*phi)) – 2*h*gamma*M_u*cos(2*phi);
D21 = h^2*gamma*H_u*sin(2*phi) + gamma*M_b*sin(2*phi) + 2*(1 – cos(2*phi)) – 2*h*gamma*M_u*cos(2*phi);
D22 = h^2*gamma*H_u*(1 + cos(2*phi)) – gamma*M_b*(1 – cos(2*phi)) + (2 + 2*h*gamma*M_u)*sin(2*phi);
D_matrix = [D11, D12;
D21, D22];
% Define stiffness matrix [K]
K11 = K_theta – h*gamma*V*H_u*(1 – cos(2*phi)) + gamma*V*M_u*sin(2*phi);
K12 = -h*V*gamma*H_u*sin(2*phi) + gamma*V*M_u*(1 + cos(2*phi));
K21 = -h*gamma*V*H_u*sin(2*phi) – gamma*V*M_u*(1 – cos(2*phi));
K22 = K_psi – h*gamma*V*H_u*(1 + cos(2*phi)) – gamma*V*M_u*sin(2*phi);
K_matrix = [K11, K12;
K21, K22];
A_top = [zeros(2, 2), eye(2)];
A_bottom = [-inv(M_matrix) * K_matrix, -inv(M_matrix) * D_matrix];
A = [A_top; A_bottom];
eigenvalues = eig(A);
% Stability condition
% Flutter
if any(real(eigenvalues) > 0)
unstable = [unstable; K_psi, K_theta];
end
% Divergence condition
if det(K_matrix) < 0
divergence_map = [divergence_map; K_psi, K_theta];
end
% 1/Ω *(Divergence) proximity check
for ev = eigenvalues’
if abs(ev – freq_1_over_Omega) < 1e-2
Rdivergence_map = [Rdivergence_map; K_psi, K_theta];
end
end
end
end
end
% Plot the Flutter and divergence maps
figure;
hold on;
scatter(unstable(:,1), unstable(:,2), ‘filled’);
scatter(divergence_map(:,1), divergence_map(:,2), ‘filled’, ‘r’);
scatter(Rdivergence_map(:, 1), Rdivergence_map(:, 2), ‘filled’, ‘g’);
xlabel(‘K_psi’);
ylabel(‘K_theta’);
title(‘Whirl Flutter Diagram’);
legend(‘Flutter area’, ‘Divergence area’, ‘ 1/Ω Divergence area’);
hold off;
I’d appreciate it if you could check it. Also, if I need to use the Floquet technique, please let me know how to modify the code. I tried to implemented the stability boundries of a 2DOF system while my coefficents are periodic.
Initially, I wrote my homogeneous matrix and directly examined the eigenvalues, but the final plot didn’t match the reference.
clc
clear all ;
% Define parameters
I_thetaoverI_b = 2 ; % Moment of inertia pitch axis over I_b
I_psioverI_b = 2 ; % Moment of inertia yaw axis over I_b
C_thetaoverI_b = 0.00; % Damping coefficient over I_b
C_psioverI_b = 0.00; % Damping coefficient over I_b
h = 0.3; % rotor mast height
hoverR = 0.34;
R = h / hoverR;
gamma = 4; % lock number
V = 325 ; % the rotor forward velocity [knots]
Omega = V/R; % the rotor rotational speed [RPM]
freq_1_over_Omega = 1 / Omega;
%the flap moment aerodynamic coefficients for large V
M_b = -(1/10)*V;
M_u = 1/6;
%the propeller aerodynamic coefficients
H_u = V/2;
%%%%%%%%%%%the flap moment aerodynamic coefficients for small V
%M_b = -1*(1 + V^2)/8 ;
%M_u = V/4;
%the propeller aerodynamic coefficients
%H_u = (V^2/2)*log(2/V);
f_pitch= 0.01:5:140;
f_yaw= 0.01:5:140;
phi_steps = linspace(0, pi, 50); % Evaluation points from 0 to pi
divergence_map = [];
Rdivergence_map = [];
unstable = [];
for i = 1:length(f_pitch)
for j = 1:length(f_yaw)
for phi = phi_steps
% Calculate stiffness for the current frequency
w_omega_pitch = 2*pi*f_pitch(i);
w_omega_yaw = 2*pi*f_yaw(j);
K_psi = (w_omega_pitch^2) * I_psioverI_b;
K_theta = (w_omega_yaw^2) * I_thetaoverI_b;
% Define inertia matrix [M]
M_matrix = [I_thetaoverI_b + 1 + cos(2*phi), -sin(2*phi);
-sin(2*phi), I_psioverI_b + 1 – cos(2*phi)];
% Define damping matrix [D]
D11 = h^2*gamma*H_u*(1 – cos(2*phi)) – gamma*M_b*(1 + cos(2*phi)) – (2 + 2*h*gamma*M_u)*sin(2*phi);
D12 = h^2*gamma*H_u*sin(2*phi) + gamma*M_b*sin(2*phi) – 2*(1 + cos(2*phi)) – 2*h*gamma*M_u*cos(2*phi);
D21 = h^2*gamma*H_u*sin(2*phi) + gamma*M_b*sin(2*phi) + 2*(1 – cos(2*phi)) – 2*h*gamma*M_u*cos(2*phi);
D22 = h^2*gamma*H_u*(1 + cos(2*phi)) – gamma*M_b*(1 – cos(2*phi)) + (2 + 2*h*gamma*M_u)*sin(2*phi);
D_matrix = [D11, D12;
D21, D22];
% Define stiffness matrix [K]
K11 = K_theta – h*gamma*V*H_u*(1 – cos(2*phi)) + gamma*V*M_u*sin(2*phi);
K12 = -h*V*gamma*H_u*sin(2*phi) + gamma*V*M_u*(1 + cos(2*phi));
K21 = -h*gamma*V*H_u*sin(2*phi) – gamma*V*M_u*(1 – cos(2*phi));
K22 = K_psi – h*gamma*V*H_u*(1 + cos(2*phi)) – gamma*V*M_u*sin(2*phi);
K_matrix = [K11, K12;
K21, K22];
A_top = [zeros(2, 2), eye(2)];
A_bottom = [-inv(M_matrix) * K_matrix, -inv(M_matrix) * D_matrix];
A = [A_top; A_bottom];
eigenvalues = eig(A);
% Stability condition
% Flutter
if any(real(eigenvalues) > 0)
unstable = [unstable; K_psi, K_theta];
end
% Divergence condition
if det(K_matrix) < 0
divergence_map = [divergence_map; K_psi, K_theta];
end
% 1/Ω *(Divergence) proximity check
for ev = eigenvalues’
if abs(ev – freq_1_over_Omega) < 1e-2
Rdivergence_map = [Rdivergence_map; K_psi, K_theta];
end
end
end
end
end
% Plot the Flutter and divergence maps
figure;
hold on;
scatter(unstable(:,1), unstable(:,2), ‘filled’);
scatter(divergence_map(:,1), divergence_map(:,2), ‘filled’, ‘r’);
scatter(Rdivergence_map(:, 1), Rdivergence_map(:, 2), ‘filled’, ‘g’);
xlabel(‘K_psi’);
ylabel(‘K_theta’);
title(‘Whirl Flutter Diagram’);
legend(‘Flutter area’, ‘Divergence area’, ‘ 1/Ω Divergence area’);
hold off;
I’d appreciate it if you could check it. Also, if I need to use the Floquet technique, please let me know how to modify the code. aeroelastic, floquet, flutter MATLAB Answers — New Questions
Poisson CDF output is all one value
I’m creating a Poisson distribution. I then want to produce a cdf evaluated at an array of values using this distribution. However, the output of the cdf matlab function when applied to a Poisson distribution is giving me all one value. I can alter that value by changing lambda of the Poisson distribution, but it’s still all one and the same.
This is my first time using Poisson distributions in Matlab, so admittedly there is a strong possiblity there is some user error involved here, but after staring at this code and rewriting it for the last two hours I’m stumped.
The code is below, along with a plot of the evaluated cdf over an array that includes 5000 points regularly spaced from 0.00001 to 0.05. The CDF value is roughly 0.95 for all evaluated points, but it should be a nice smooth ‘S’ shape starting at 0 and climbing up as the XX value increases. Why am I getting this nonsensical output?
Computer is a Dell laptop running Windows 10.
XX = 0.00001:0.00001:0.05;
p = makedist(‘Poisson’,’lambda’,0.05);
C = cdf(p,XX);
plot(C)I’m creating a Poisson distribution. I then want to produce a cdf evaluated at an array of values using this distribution. However, the output of the cdf matlab function when applied to a Poisson distribution is giving me all one value. I can alter that value by changing lambda of the Poisson distribution, but it’s still all one and the same.
This is my first time using Poisson distributions in Matlab, so admittedly there is a strong possiblity there is some user error involved here, but after staring at this code and rewriting it for the last two hours I’m stumped.
The code is below, along with a plot of the evaluated cdf over an array that includes 5000 points regularly spaced from 0.00001 to 0.05. The CDF value is roughly 0.95 for all evaluated points, but it should be a nice smooth ‘S’ shape starting at 0 and climbing up as the XX value increases. Why am I getting this nonsensical output?
Computer is a Dell laptop running Windows 10.
XX = 0.00001:0.00001:0.05;
p = makedist(‘Poisson’,’lambda’,0.05);
C = cdf(p,XX);
plot(C) I’m creating a Poisson distribution. I then want to produce a cdf evaluated at an array of values using this distribution. However, the output of the cdf matlab function when applied to a Poisson distribution is giving me all one value. I can alter that value by changing lambda of the Poisson distribution, but it’s still all one and the same.
This is my first time using Poisson distributions in Matlab, so admittedly there is a strong possiblity there is some user error involved here, but after staring at this code and rewriting it for the last two hours I’m stumped.
The code is below, along with a plot of the evaluated cdf over an array that includes 5000 points regularly spaced from 0.00001 to 0.05. The CDF value is roughly 0.95 for all evaluated points, but it should be a nice smooth ‘S’ shape starting at 0 and climbing up as the XX value increases. Why am I getting this nonsensical output?
Computer is a Dell laptop running Windows 10.
XX = 0.00001:0.00001:0.05;
p = makedist(‘Poisson’,’lambda’,0.05);
C = cdf(p,XX);
plot(C) poisson, cdf, pdf, makedist, fitdist MATLAB Answers — New Questions
Does SoC Model Creator support only Vivado 2020.2?
I am using Vivado 2023.2 and getting an error when creating a project using SoC Model Builder.
"Vivado version 2023.1 on system path not supported. Supported tool version is 2020.2. Use the hdlsetuptoolpath function to add the appropriate synthesis tool path to your system path for the current MATLAB session."I am using Vivado 2023.2 and getting an error when creating a project using SoC Model Builder.
"Vivado version 2023.1 on system path not supported. Supported tool version is 2020.2. Use the hdlsetuptoolpath function to add the appropriate synthesis tool path to your system path for the current MATLAB session." I am using Vivado 2023.2 and getting an error when creating a project using SoC Model Builder.
"Vivado version 2023.1 on system path not supported. Supported tool version is 2020.2. Use the hdlsetuptoolpath function to add the appropriate synthesis tool path to your system path for the current MATLAB session." socmodelcreator, vivado MATLAB Answers — New Questions
the use of field graphing tools
K = 8.99e9;
% Input the number of charges
n = input(‘Enter number of charges: ‘);
% Initialize arrays to store charge values and coordinates
q = zeros(1, n);
x = zeros(1, n);
y = zeros(1, n);
minx = Inf;
maxx = -Inf;
miny = Inf;
maxy = -Inf;
% Input charge values
for i = 1:n
q(i) = input([‘Enter the charge in coulombs for charge ‘, num2str(i), ‘: ‘]);
end
% Input coordinates of the charges
for i = 1:n
x(i) = input([‘Enter x coordinate for charge ‘, num2str(i), ‘: ‘]);
y(i) = input([‘Enter y coordinate for charge ‘, num2str(i), ‘: ‘]);
if x(i) > maxx
maxx = x(i);
end
if x(i) < minx
minx = x(i);
end
if y(i) > maxy
maxy = y(i);
end
if y(i) < miny
miny = y(i);
end
end
% Define the grid for visualization
[X, Y] = meshgrid((minx-1):0.1:(maxx+1), (miny-1):0.1:(maxy+1));
Ex = zeros(size(X));
Ey = zeros(size(X));
% Calculate the electric field components
for i = 1:n
R = ((X – x(i)).^2 + (Y – y(i)).^2 ).^1.5; % Distance cubed
Ex = Ex + K * q(i) * (X – x(i)) ./ R;
Ey = Ey + K * q(i) * (Y – y(i)) ./ R;
end
% Plot the electric field vectors
figure;
quiver(X, Y, Ex, Ey);
xlabel(‘x (m)’);
ylabel(‘y (m)’);
title(‘Electric Field Vectors’);
axis equal;
grid on;
% Plot the potential distribution (if needed)
% Potential at each point
V = zeros(size(X));
for i = 1:n
R = sqrt((X – x(i)).^2 + (Y – y(i)).^2 ); % Distance
V = V + K * q(i) ./ R;
end
figure;
contourf(X, Y, V, 50, ‘LineColor’, ‘none’);
colorbar;
xlabel(‘x (m)’);
ylabel(‘y (m)’);
title(‘Potential Distribution’);
axis equal;
grid on;
i wrote the following code and i am trying to improve a couple of things
1 i want the graph to fit the boundaries so it wont draw a grid that has field lines in parts and the rest is grid
2 when i enter a negative point charge it gets problamatic this is physically correct but i want to try and write something to deal with it
3 the field lines are write but they do not really reflect the behavoir well especially when i write something like 3 + and -1 on a destince 1 from each other they look just like 1 and -1 a bit better in the voltage aspect
now this is for improvment that seem okayish yet from my trial and error i could not implement
now the problamtic request is for the next part of the code i am trying to write i am trying to draw a visullization of the field between 2 finite planes
i started this part by writing an approximation for the derivative and checking that it works
h = logspace(-1,-15,100);
real_d = -sin(1);
real_d2 = -sin(1+h);
di_d = (cos(1+h)-cos(1))./h ;
simt_d = (cos(1+h)-cos(1-h))./(2*h) ;
plot (log10(h) , log10(real_d – di_d),’*’)
hold on
plot (log10(h) , log10(real_d – simt_d),’*’)
hold o
xlabel ("log(h) from x=1")
ylabel ("log(di) from -sin(1)")
i derived the equations i need
yet i am having a hard time trying to implment them
% Constants
d = 0.5; % distance between plates in cm
R = 10.0; % radius of the plates in cm
V = 1.0; % potential difference in V
h = d / 20; % step size in cm
r_max = R + 5 * d; % maximum r value in cm
z_max = 10 * d; % maximum z value in cm
tolerance = 0.0001; % convergence criterion (0.01%)
% Define the grid
r_points = floor(r_max / h) + 1;
z_points = 2 * floor(z_max / h) + 1;
phi = zeros(r_points, z_points);
% Set boundary conditions for the finite plates
for i = 1:floor(R / h) + 1
% Positive plate at z = d/2
phi(i, floor(z_max / h) + 1 + floor(d / (2 * h))) = 0.5 * V;
% Negative plate at z = -d/2
phi(i, floor(z_max / h) + 1 – floor(d / (2 * h))) = -0.5 * V;
end
% Relaxation method
max_diff = tolerance + 1; % Initialize max difference
while max_diff > tolerance
max_diff = 0;
phi_new = phi;
for i = 2:r_points-1
for j = 2:z_points-1
% Skip the points on the plates
if (i * h <= R) && (j == floor(z_max / h) + 1 + floor(d / (2 * h)) || j == floor(z_max / h) + 1 – floor(d / (2 * h)))
continue;
end
phi_new(i, j) = 0.25 * ( …
phi(i + 1, j) * (1 + h / (2 * (i * h))) + …
phi(i – 1, j) * (1 – h / (2 * (i * h))) + …
phi(i, j + 1) + …
phi(i, j – 1));
max_diff = max(max_diff, abs(phi_new(i, j) – phi(i, j)));
end
end
phi = phi_new;
end
% Plotting the potential
r = 0:h:r_max;
z = -z_max:h:z_max;
[R, Z] = meshgrid(r, z);
figure;
contourf(R, Z, phi’, 50, ‘LineColor’, ‘none’);
colorbar;
xlabel(‘r (cm)’);
ylabel(‘z (cm)’);
title(‘Electric Potential in the r-z Plane’);
the drawing seems weird too if some one can give a bit of guidenss on the use of relaxationK = 8.99e9;
% Input the number of charges
n = input(‘Enter number of charges: ‘);
% Initialize arrays to store charge values and coordinates
q = zeros(1, n);
x = zeros(1, n);
y = zeros(1, n);
minx = Inf;
maxx = -Inf;
miny = Inf;
maxy = -Inf;
% Input charge values
for i = 1:n
q(i) = input([‘Enter the charge in coulombs for charge ‘, num2str(i), ‘: ‘]);
end
% Input coordinates of the charges
for i = 1:n
x(i) = input([‘Enter x coordinate for charge ‘, num2str(i), ‘: ‘]);
y(i) = input([‘Enter y coordinate for charge ‘, num2str(i), ‘: ‘]);
if x(i) > maxx
maxx = x(i);
end
if x(i) < minx
minx = x(i);
end
if y(i) > maxy
maxy = y(i);
end
if y(i) < miny
miny = y(i);
end
end
% Define the grid for visualization
[X, Y] = meshgrid((minx-1):0.1:(maxx+1), (miny-1):0.1:(maxy+1));
Ex = zeros(size(X));
Ey = zeros(size(X));
% Calculate the electric field components
for i = 1:n
R = ((X – x(i)).^2 + (Y – y(i)).^2 ).^1.5; % Distance cubed
Ex = Ex + K * q(i) * (X – x(i)) ./ R;
Ey = Ey + K * q(i) * (Y – y(i)) ./ R;
end
% Plot the electric field vectors
figure;
quiver(X, Y, Ex, Ey);
xlabel(‘x (m)’);
ylabel(‘y (m)’);
title(‘Electric Field Vectors’);
axis equal;
grid on;
% Plot the potential distribution (if needed)
% Potential at each point
V = zeros(size(X));
for i = 1:n
R = sqrt((X – x(i)).^2 + (Y – y(i)).^2 ); % Distance
V = V + K * q(i) ./ R;
end
figure;
contourf(X, Y, V, 50, ‘LineColor’, ‘none’);
colorbar;
xlabel(‘x (m)’);
ylabel(‘y (m)’);
title(‘Potential Distribution’);
axis equal;
grid on;
i wrote the following code and i am trying to improve a couple of things
1 i want the graph to fit the boundaries so it wont draw a grid that has field lines in parts and the rest is grid
2 when i enter a negative point charge it gets problamatic this is physically correct but i want to try and write something to deal with it
3 the field lines are write but they do not really reflect the behavoir well especially when i write something like 3 + and -1 on a destince 1 from each other they look just like 1 and -1 a bit better in the voltage aspect
now this is for improvment that seem okayish yet from my trial and error i could not implement
now the problamtic request is for the next part of the code i am trying to write i am trying to draw a visullization of the field between 2 finite planes
i started this part by writing an approximation for the derivative and checking that it works
h = logspace(-1,-15,100);
real_d = -sin(1);
real_d2 = -sin(1+h);
di_d = (cos(1+h)-cos(1))./h ;
simt_d = (cos(1+h)-cos(1-h))./(2*h) ;
plot (log10(h) , log10(real_d – di_d),’*’)
hold on
plot (log10(h) , log10(real_d – simt_d),’*’)
hold o
xlabel ("log(h) from x=1")
ylabel ("log(di) from -sin(1)")
i derived the equations i need
yet i am having a hard time trying to implment them
% Constants
d = 0.5; % distance between plates in cm
R = 10.0; % radius of the plates in cm
V = 1.0; % potential difference in V
h = d / 20; % step size in cm
r_max = R + 5 * d; % maximum r value in cm
z_max = 10 * d; % maximum z value in cm
tolerance = 0.0001; % convergence criterion (0.01%)
% Define the grid
r_points = floor(r_max / h) + 1;
z_points = 2 * floor(z_max / h) + 1;
phi = zeros(r_points, z_points);
% Set boundary conditions for the finite plates
for i = 1:floor(R / h) + 1
% Positive plate at z = d/2
phi(i, floor(z_max / h) + 1 + floor(d / (2 * h))) = 0.5 * V;
% Negative plate at z = -d/2
phi(i, floor(z_max / h) + 1 – floor(d / (2 * h))) = -0.5 * V;
end
% Relaxation method
max_diff = tolerance + 1; % Initialize max difference
while max_diff > tolerance
max_diff = 0;
phi_new = phi;
for i = 2:r_points-1
for j = 2:z_points-1
% Skip the points on the plates
if (i * h <= R) && (j == floor(z_max / h) + 1 + floor(d / (2 * h)) || j == floor(z_max / h) + 1 – floor(d / (2 * h)))
continue;
end
phi_new(i, j) = 0.25 * ( …
phi(i + 1, j) * (1 + h / (2 * (i * h))) + …
phi(i – 1, j) * (1 – h / (2 * (i * h))) + …
phi(i, j + 1) + …
phi(i, j – 1));
max_diff = max(max_diff, abs(phi_new(i, j) – phi(i, j)));
end
end
phi = phi_new;
end
% Plotting the potential
r = 0:h:r_max;
z = -z_max:h:z_max;
[R, Z] = meshgrid(r, z);
figure;
contourf(R, Z, phi’, 50, ‘LineColor’, ‘none’);
colorbar;
xlabel(‘r (cm)’);
ylabel(‘z (cm)’);
title(‘Electric Potential in the r-z Plane’);
the drawing seems weird too if some one can give a bit of guidenss on the use of relaxation K = 8.99e9;
% Input the number of charges
n = input(‘Enter number of charges: ‘);
% Initialize arrays to store charge values and coordinates
q = zeros(1, n);
x = zeros(1, n);
y = zeros(1, n);
minx = Inf;
maxx = -Inf;
miny = Inf;
maxy = -Inf;
% Input charge values
for i = 1:n
q(i) = input([‘Enter the charge in coulombs for charge ‘, num2str(i), ‘: ‘]);
end
% Input coordinates of the charges
for i = 1:n
x(i) = input([‘Enter x coordinate for charge ‘, num2str(i), ‘: ‘]);
y(i) = input([‘Enter y coordinate for charge ‘, num2str(i), ‘: ‘]);
if x(i) > maxx
maxx = x(i);
end
if x(i) < minx
minx = x(i);
end
if y(i) > maxy
maxy = y(i);
end
if y(i) < miny
miny = y(i);
end
end
% Define the grid for visualization
[X, Y] = meshgrid((minx-1):0.1:(maxx+1), (miny-1):0.1:(maxy+1));
Ex = zeros(size(X));
Ey = zeros(size(X));
% Calculate the electric field components
for i = 1:n
R = ((X – x(i)).^2 + (Y – y(i)).^2 ).^1.5; % Distance cubed
Ex = Ex + K * q(i) * (X – x(i)) ./ R;
Ey = Ey + K * q(i) * (Y – y(i)) ./ R;
end
% Plot the electric field vectors
figure;
quiver(X, Y, Ex, Ey);
xlabel(‘x (m)’);
ylabel(‘y (m)’);
title(‘Electric Field Vectors’);
axis equal;
grid on;
% Plot the potential distribution (if needed)
% Potential at each point
V = zeros(size(X));
for i = 1:n
R = sqrt((X – x(i)).^2 + (Y – y(i)).^2 ); % Distance
V = V + K * q(i) ./ R;
end
figure;
contourf(X, Y, V, 50, ‘LineColor’, ‘none’);
colorbar;
xlabel(‘x (m)’);
ylabel(‘y (m)’);
title(‘Potential Distribution’);
axis equal;
grid on;
i wrote the following code and i am trying to improve a couple of things
1 i want the graph to fit the boundaries so it wont draw a grid that has field lines in parts and the rest is grid
2 when i enter a negative point charge it gets problamatic this is physically correct but i want to try and write something to deal with it
3 the field lines are write but they do not really reflect the behavoir well especially when i write something like 3 + and -1 on a destince 1 from each other they look just like 1 and -1 a bit better in the voltage aspect
now this is for improvment that seem okayish yet from my trial and error i could not implement
now the problamtic request is for the next part of the code i am trying to write i am trying to draw a visullization of the field between 2 finite planes
i started this part by writing an approximation for the derivative and checking that it works
h = logspace(-1,-15,100);
real_d = -sin(1);
real_d2 = -sin(1+h);
di_d = (cos(1+h)-cos(1))./h ;
simt_d = (cos(1+h)-cos(1-h))./(2*h) ;
plot (log10(h) , log10(real_d – di_d),’*’)
hold on
plot (log10(h) , log10(real_d – simt_d),’*’)
hold o
xlabel ("log(h) from x=1")
ylabel ("log(di) from -sin(1)")
i derived the equations i need
yet i am having a hard time trying to implment them
% Constants
d = 0.5; % distance between plates in cm
R = 10.0; % radius of the plates in cm
V = 1.0; % potential difference in V
h = d / 20; % step size in cm
r_max = R + 5 * d; % maximum r value in cm
z_max = 10 * d; % maximum z value in cm
tolerance = 0.0001; % convergence criterion (0.01%)
% Define the grid
r_points = floor(r_max / h) + 1;
z_points = 2 * floor(z_max / h) + 1;
phi = zeros(r_points, z_points);
% Set boundary conditions for the finite plates
for i = 1:floor(R / h) + 1
% Positive plate at z = d/2
phi(i, floor(z_max / h) + 1 + floor(d / (2 * h))) = 0.5 * V;
% Negative plate at z = -d/2
phi(i, floor(z_max / h) + 1 – floor(d / (2 * h))) = -0.5 * V;
end
% Relaxation method
max_diff = tolerance + 1; % Initialize max difference
while max_diff > tolerance
max_diff = 0;
phi_new = phi;
for i = 2:r_points-1
for j = 2:z_points-1
% Skip the points on the plates
if (i * h <= R) && (j == floor(z_max / h) + 1 + floor(d / (2 * h)) || j == floor(z_max / h) + 1 – floor(d / (2 * h)))
continue;
end
phi_new(i, j) = 0.25 * ( …
phi(i + 1, j) * (1 + h / (2 * (i * h))) + …
phi(i – 1, j) * (1 – h / (2 * (i * h))) + …
phi(i, j + 1) + …
phi(i, j – 1));
max_diff = max(max_diff, abs(phi_new(i, j) – phi(i, j)));
end
end
phi = phi_new;
end
% Plotting the potential
r = 0:h:r_max;
z = -z_max:h:z_max;
[R, Z] = meshgrid(r, z);
figure;
contourf(R, Z, phi’, 50, ‘LineColor’, ‘none’);
colorbar;
xlabel(‘r (cm)’);
ylabel(‘z (cm)’);
title(‘Electric Potential in the r-z Plane’);
the drawing seems weird too if some one can give a bit of guidenss on the use of relaxation plotting MATLAB Answers — New Questions
Matlab Coder Windows -> Linux cross-compilation
Version: Matlab 2019b
Task: from Windows compile Linux static library (.a) to be used in Android application.
Current state: on Windows Matlab Coder allows generation of .lib, .dll only.
I saw there are threads for cross-compilation, does anyone made it work and can provide detailed instruction?Version: Matlab 2019b
Task: from Windows compile Linux static library (.a) to be used in Android application.
Current state: on Windows Matlab Coder allows generation of .lib, .dll only.
I saw there are threads for cross-compilation, does anyone made it work and can provide detailed instruction? Version: Matlab 2019b
Task: from Windows compile Linux static library (.a) to be used in Android application.
Current state: on Windows Matlab Coder allows generation of .lib, .dll only.
I saw there are threads for cross-compilation, does anyone made it work and can provide detailed instruction? matlab coder, cross-compilation MATLAB Answers — New Questions
Why does the error at the bottom show up even though the correct dataset seems to be selected?
It says "Unable to find suitable response variable ~"
Here is the code:
img = imread("C:UsersxxooxOneDriveデスクトップMATLAB worksDataMathWorks Imagesocean.jpg"); % Load the unlabeled image
load ("C:UsersxxooxOneDriveデスクトップMATLAB worksComputer Vision for Engineering and ScienceC2-MachineLearningForComputerVisionModule 2gcClassifierSaturation.mat","gcClassifierSaturation") % Load the model trained using hand-selected features
load ("C:UsersxxooxOneDriveデスクトップMATLAB worksComputer Vision for Engineering and ScienceC2-MachineLearningForComputerVisionModule 2gcClassifierBag.mat","gcClassifierBag") % Load the model trained using automatically generated features
load ("C:UsersxxooxOneDriveデスクトップMATLAB worksComputer Vision for Engineering and ScienceC2-MachineLearningForComputerVisionModule 2bag.mat","bag") % Load bag of visual words object created by bagOfFeatures
% Step 1: Create a table of saturation-based predictor features
% Convert the image to HSV color space
hsvImg = rgb2hsv(img);
% Extract the saturation channel
saturation = hsvImg(:,:,2);
% Calculate the mean and standard deviation of the saturation
avgSat = mean(saturation(:));
stdSat = std(saturation(:));
% Create a table of saturation-based predictor features
gcTableSaturation = table(avgSat, stdSat);
% Step 2: Use gcClassifierSaturation.predictFcn to classify the unlabeled image
% Use the classifier to predict the label
prediction = gcClassifierSaturation.predictFcn(gcTableSaturation);
% Attach the prediction to the table
gcTableSaturation.prediction = prediction;
% Step 3: Create a table of bagOfFeatures-based predictor features
% Encode the image using the bag of features
featureVector = encode(bag, img);
% Create a table of predictor features for the unlabeled image
gcTableBag = array2table(featureVector);
gcTableBag.Properties.VariableNames = arrayfun(@(x) [‘f’ num2str(x)], 1:500, ‘UniformOutput’, false);
% Step 4: Use gcClassifierBag.predictFcn to classify the unlabeled image
% Use the classifier to predict the label
predictionBag = gcClassifierBag.predictFcn(gcTableBag);
% Attach the prediction to the table
gcTableBag.prediction = predictionBag;It says "Unable to find suitable response variable ~"
Here is the code:
img = imread("C:UsersxxooxOneDriveデスクトップMATLAB worksDataMathWorks Imagesocean.jpg"); % Load the unlabeled image
load ("C:UsersxxooxOneDriveデスクトップMATLAB worksComputer Vision for Engineering and ScienceC2-MachineLearningForComputerVisionModule 2gcClassifierSaturation.mat","gcClassifierSaturation") % Load the model trained using hand-selected features
load ("C:UsersxxooxOneDriveデスクトップMATLAB worksComputer Vision for Engineering and ScienceC2-MachineLearningForComputerVisionModule 2gcClassifierBag.mat","gcClassifierBag") % Load the model trained using automatically generated features
load ("C:UsersxxooxOneDriveデスクトップMATLAB worksComputer Vision for Engineering and ScienceC2-MachineLearningForComputerVisionModule 2bag.mat","bag") % Load bag of visual words object created by bagOfFeatures
% Step 1: Create a table of saturation-based predictor features
% Convert the image to HSV color space
hsvImg = rgb2hsv(img);
% Extract the saturation channel
saturation = hsvImg(:,:,2);
% Calculate the mean and standard deviation of the saturation
avgSat = mean(saturation(:));
stdSat = std(saturation(:));
% Create a table of saturation-based predictor features
gcTableSaturation = table(avgSat, stdSat);
% Step 2: Use gcClassifierSaturation.predictFcn to classify the unlabeled image
% Use the classifier to predict the label
prediction = gcClassifierSaturation.predictFcn(gcTableSaturation);
% Attach the prediction to the table
gcTableSaturation.prediction = prediction;
% Step 3: Create a table of bagOfFeatures-based predictor features
% Encode the image using the bag of features
featureVector = encode(bag, img);
% Create a table of predictor features for the unlabeled image
gcTableBag = array2table(featureVector);
gcTableBag.Properties.VariableNames = arrayfun(@(x) [‘f’ num2str(x)], 1:500, ‘UniformOutput’, false);
% Step 4: Use gcClassifierBag.predictFcn to classify the unlabeled image
% Use the classifier to predict the label
predictionBag = gcClassifierBag.predictFcn(gcTableBag);
% Attach the prediction to the table
gcTableBag.prediction = predictionBag; It says "Unable to find suitable response variable ~"
Here is the code:
img = imread("C:UsersxxooxOneDriveデスクトップMATLAB worksDataMathWorks Imagesocean.jpg"); % Load the unlabeled image
load ("C:UsersxxooxOneDriveデスクトップMATLAB worksComputer Vision for Engineering and ScienceC2-MachineLearningForComputerVisionModule 2gcClassifierSaturation.mat","gcClassifierSaturation") % Load the model trained using hand-selected features
load ("C:UsersxxooxOneDriveデスクトップMATLAB worksComputer Vision for Engineering and ScienceC2-MachineLearningForComputerVisionModule 2gcClassifierBag.mat","gcClassifierBag") % Load the model trained using automatically generated features
load ("C:UsersxxooxOneDriveデスクトップMATLAB worksComputer Vision for Engineering and ScienceC2-MachineLearningForComputerVisionModule 2bag.mat","bag") % Load bag of visual words object created by bagOfFeatures
% Step 1: Create a table of saturation-based predictor features
% Convert the image to HSV color space
hsvImg = rgb2hsv(img);
% Extract the saturation channel
saturation = hsvImg(:,:,2);
% Calculate the mean and standard deviation of the saturation
avgSat = mean(saturation(:));
stdSat = std(saturation(:));
% Create a table of saturation-based predictor features
gcTableSaturation = table(avgSat, stdSat);
% Step 2: Use gcClassifierSaturation.predictFcn to classify the unlabeled image
% Use the classifier to predict the label
prediction = gcClassifierSaturation.predictFcn(gcTableSaturation);
% Attach the prediction to the table
gcTableSaturation.prediction = prediction;
% Step 3: Create a table of bagOfFeatures-based predictor features
% Encode the image using the bag of features
featureVector = encode(bag, img);
% Create a table of predictor features for the unlabeled image
gcTableBag = array2table(featureVector);
gcTableBag.Properties.VariableNames = arrayfun(@(x) [‘f’ num2str(x)], 1:500, ‘UniformOutput’, false);
% Step 4: Use gcClassifierBag.predictFcn to classify the unlabeled image
% Use the classifier to predict the label
predictionBag = gcClassifierBag.predictFcn(gcTableBag);
% Attach the prediction to the table
gcTableBag.prediction = predictionBag; matlab, machine learning, image classification MATLAB Answers — New Questions
Warning: Error using Simulink.SLXPart (line 74)
Hello,
recently, i keep getting this warning whenever i run or save my simulink model:
Warning: Error using Simulink.SLXPart (line 74)
Part name must start with a slash
Error in slxPackager/partDefResources>i_partinfo
Error in slxPackager/partDefResources>i_save
Error in Simulink.SLXPartHandler/pExecute (line 105)
feval(cb,packager);
Error in Simulink.SLXPartHandler/doSave (line 66)
pExecute(obj(i),packager,cb,’Save’,logger);
Error in Simulink.SLXPartHandlerRegistrar/executeSaveCallbacks (line 94)
doSave(obj.getHandlers,packager);
Error in slxPackager/executeSaveCallbacks
Error in slxPackager/save
Error in slprivate (line 11)
[varargout{1:nargout}] = feval(function_name, varargin{1:end});
Error in SimulinkStudio.callbacks.saveCB (line 14)
SLM3I.saveBlockDiagram( cbinfo.model.Handle );
Error in SLStudio.ToolBars
Please give me some tipps on how to solve this issue, thanks 🙂
BrianHello,
recently, i keep getting this warning whenever i run or save my simulink model:
Warning: Error using Simulink.SLXPart (line 74)
Part name must start with a slash
Error in slxPackager/partDefResources>i_partinfo
Error in slxPackager/partDefResources>i_save
Error in Simulink.SLXPartHandler/pExecute (line 105)
feval(cb,packager);
Error in Simulink.SLXPartHandler/doSave (line 66)
pExecute(obj(i),packager,cb,’Save’,logger);
Error in Simulink.SLXPartHandlerRegistrar/executeSaveCallbacks (line 94)
doSave(obj.getHandlers,packager);
Error in slxPackager/executeSaveCallbacks
Error in slxPackager/save
Error in slprivate (line 11)
[varargout{1:nargout}] = feval(function_name, varargin{1:end});
Error in SimulinkStudio.callbacks.saveCB (line 14)
SLM3I.saveBlockDiagram( cbinfo.model.Handle );
Error in SLStudio.ToolBars
Please give me some tipps on how to solve this issue, thanks 🙂
Brian Hello,
recently, i keep getting this warning whenever i run or save my simulink model:
Warning: Error using Simulink.SLXPart (line 74)
Part name must start with a slash
Error in slxPackager/partDefResources>i_partinfo
Error in slxPackager/partDefResources>i_save
Error in Simulink.SLXPartHandler/pExecute (line 105)
feval(cb,packager);
Error in Simulink.SLXPartHandler/doSave (line 66)
pExecute(obj(i),packager,cb,’Save’,logger);
Error in Simulink.SLXPartHandlerRegistrar/executeSaveCallbacks (line 94)
doSave(obj.getHandlers,packager);
Error in slxPackager/executeSaveCallbacks
Error in slxPackager/save
Error in slprivate (line 11)
[varargout{1:nargout}] = feval(function_name, varargin{1:end});
Error in SimulinkStudio.callbacks.saveCB (line 14)
SLM3I.saveBlockDiagram( cbinfo.model.Handle );
Error in SLStudio.ToolBars
Please give me some tipps on how to solve this issue, thanks 🙂
Brian simulink MATLAB Answers — New Questions
Pendulum using Crank-Nicolson
Hi everybody,
I’m relatively new to MatLab, and to numerical analysis in general. I have this problem I have to solve, using the Crank-Nicolson method, and I don’t have the slightest idea how to start my code…
I’m trying to solve two non-linear forced pendulum equation, which I adimensionalized as follows :
Can anyone give me a hint on how to start my process?
Thanks!
KenaHi everybody,
I’m relatively new to MatLab, and to numerical analysis in general. I have this problem I have to solve, using the Crank-Nicolson method, and I don’t have the slightest idea how to start my code…
I’m trying to solve two non-linear forced pendulum equation, which I adimensionalized as follows :
Can anyone give me a hint on how to start my process?
Thanks!
Kena Hi everybody,
I’m relatively new to MatLab, and to numerical analysis in general. I have this problem I have to solve, using the Crank-Nicolson method, and I don’t have the slightest idea how to start my code…
I’m trying to solve two non-linear forced pendulum equation, which I adimensionalized as follows :
Can anyone give me a hint on how to start my process?
Thanks!
Kena matlab, crank, nicolson, nonlinear, method MATLAB Answers — New Questions
How to plot a line on top of the continuous wavelet transform (CWT) output?
Hello. According to the attached figure, I want to add a horizontal green line (at a scale of 60) on top of the continuous wavelet transform (CWT) output. However, the line is positioned below the CWT output. Your assistance with this request would be greatly appreciated.Hello. According to the attached figure, I want to add a horizontal green line (at a scale of 60) on top of the continuous wavelet transform (CWT) output. However, the line is positioned below the CWT output. Your assistance with this request would be greatly appreciated. Hello. According to the attached figure, I want to add a horizontal green line (at a scale of 60) on top of the continuous wavelet transform (CWT) output. However, the line is positioned below the CWT output. Your assistance with this request would be greatly appreciated. plot MATLAB Answers — New Questions
problem doing implicit plotting
Hi, I am trying to make an implicit 3D plot in Matlab. A Matlab Help page says to use the following (as an example):
f = @(x,y,z) x.^2 + y.^2 – z.^2;
interval = [-5 5 -5 5 0 5];
fimplicit3(f,interval)
This works fine. But if I try to complicate things a bit by changing f to:
f = @(x,y,z) x.^2 + y.^2 – z.^2 + x.*y.
then I get the error message "Error: Invalid expression. Check for missing or extra characters".
Any idea what the problem is?
Thank you!Hi, I am trying to make an implicit 3D plot in Matlab. A Matlab Help page says to use the following (as an example):
f = @(x,y,z) x.^2 + y.^2 – z.^2;
interval = [-5 5 -5 5 0 5];
fimplicit3(f,interval)
This works fine. But if I try to complicate things a bit by changing f to:
f = @(x,y,z) x.^2 + y.^2 – z.^2 + x.*y.
then I get the error message "Error: Invalid expression. Check for missing or extra characters".
Any idea what the problem is?
Thank you! Hi, I am trying to make an implicit 3D plot in Matlab. A Matlab Help page says to use the following (as an example):
f = @(x,y,z) x.^2 + y.^2 – z.^2;
interval = [-5 5 -5 5 0 5];
fimplicit3(f,interval)
This works fine. But if I try to complicate things a bit by changing f to:
f = @(x,y,z) x.^2 + y.^2 – z.^2 + x.*y.
then I get the error message "Error: Invalid expression. Check for missing or extra characters".
Any idea what the problem is?
Thank you! plot MATLAB Answers — New Questions