**Pull up a chair!**

Discussions is **your** place to get to know your peers, tackle the bigger challenges together, and have fun along the way.

- Want to see the latest updates? Follow the Highlights!
- Looking for techniques improve your MATLAB or Simulink skills? Tips & Tricks has you covered!
- Sharing the perfect math joke, pun, or meme? Look no further than Fun!
- Think there's a channel we need? Tell us more in Ideas

## Newest Discussions

Hi, I have a table looking for a way to calculate the UserAcceleration of a mobile phone and as input I have array of yaw, pitch, roll (in degrees).

I've managed to calculate gravity(x, y, z) m/s^2 and rotation rate(x, y, z) in degree/s but not the angular acceleration, here are my calculations until now:

https://pastebin.com/raw/MEbhBnkE

Could someone help me to calculate user acceleration as well?

Thanks

Hi everyone,

for my thesis project I would need to get, every second of the simulation, real-time output data from a Simulink model, without using Simulink Real-Time, as it supports only Speedgoat Hardware. Is there a particular set of blocks for that purpose?

I have to provide that real-time data to hardware for an Hardware in the Loop Simulation so I will need to be able also to receive, as an input, data from the hardware to the Simulink model, again every second of the simulation, to close the loop of the simulation.

Thank you in advance for your support.

Hello Everyone.

I am trying to solve lid driven cavity flow problem by solving Navier stokes equation using the following code. It is providing me wrong values for example it is exceeding the max possible velocity which is the top surface velocity i.e. 1 in my case. Can anyone suggest me what change can I make here. It will be very helpful.I am stuck into it since long.

clc,clear

% Lid-driven cavity flow simulation

% Numerical solution of Navier-Stokes equations

%Author Tushar Nath

%Dec 2023

%We will use different values of kinematic viscosity neu to check the flow

%characteristics at different Reynolds number

% Parameters

L = 1; % Length of the square cavity

u_top = 1; % Lid velocity

u_bot=0; u_lef=0; u_rig=0; %No slip

v_top=0; %No Vertical component of the velocity

v_bot=0; v_lef=0; v_rig=0; %No Slip

rho=1; % Density

neu= 1/400; % kinematic viscosity for Re=400

nx=100;

ny=100;

% Time parameters

dt = 0.001; % Time step

T = 0.05; % Total simulation time

Nt = round(T/dt); % Number of time steps

La=zeros(nx*ny,nx*ny); %Laplacian Operator poisson Equation

% Staggered Grid

imin=2; imax=imin+nx-1;

jmin=2; jmax=jmin+ny-1;

% Create mesh

x( imin:imax+1)=linspace (0, L, nx+1);

y( jmin:jmax+1)=linspace (0, L, ny+1);

xm(imin:imax )=0.5*(x(imin:imax)+x(imin+1:imax+1));

ym(jmin:jmax )=0.5*(y(jmin:jmax)+y(jmin+1: jmax+1)) ;

% Create mesh sizes

dx=x(imin+1)-x(imin ) ;

dy=y(jmin+1)-y(jmin ) ;

dxi=1/dx ;

dyi=1/dy ;

% disp(dx);

% disp(dy);

% disp(dxi);

% disp(dyi);

%Laplace Operator

for j =1:ny

for i =1:nx

La(i+( j -1)*nx , i+( j -1)*nx)=2*dxi^2+2*dyi^ 2 ;

for ii=i -1:2: i+1

if ( ii >0 && ii <=nx) % interior point

La( i+( j -1)*nx , ii +( j -1)*nx)=-dxi^ 2 ;

else % Neuman conditions on boundary

La( i+( j -1)*nx , i +(j -1)*nx)=La( i+( j -1)*nx , i +( j -1)*nx)-dxi^2;

end

end

for jj=j -1:2: j+1

if ( jj >0 && jj<=ny) % interior point

La( i+( j-1)*nx , i+( jj -1)*nx)=-dyi^ 2;

else % Neuman conditions on boundary

La( i+( j -1)*nx , i+( j -1)*nx)=La( i+( j -1)*nx , i+( j -1)*nx)-dyi^ 2;

end

end

end

end

% Set pressure in the first cell ( All other pressure w.r.t. This one)

La( 1 , : )=0 ; La(1 ,1)=1;

%Initialize Array for Pressures

p=zeros( imax , jmax );

%Initialize array for u,up,v,vp

u=zeros(imax+1);

up=zeros(imax+1);

v=zeros(jmax+1);

vp=zeros(jmax+1);

%Iterate with time

for n=1:Nt

%Apply BC

u ( : , jmin-1)=-u (: , jmin)+2*u_bot;

u ( : , jmax+1)=-u ( : , jmax)+2*u_top;

v ( imin -1,:)=-v(imin , :)+2*v_lef;

v ( imax+1,:)=-v(imax , :)+2*v_rig;

%x-velocity predictor

for j=jmin : jmax

for i=imin+1: imax

v_ave=0.25*(v( i -1, j)+v(i -1, j+1)+v(i , j)+v(i , j +1)) ;

up(i , j) =u(i , j )+dt *(neu*(u(i -1, j)-2*u(i , j)+u(i +1, j))*dxi^2 ...

+neu*(u( i , j -1)-2*u(i , j )+ ...

u(i , j +1))*dyi^2 -u(i , j )*( u(i +1, j )-u(i -1, j ) ) * 0.5 * dxi -v_ave*(u(i , j+1)-u(i , j -1) )*0.5* dyi ) ;

end

end

% disp(up);

%y-velocity predictor

for j=jmin+1: jmax

for i=imin : imax

u_ave =0.25*(u( i , j-1)+u( i , j )+u( i +1, j-1)+u( i +1, j ) ) ;

vp(i ,j) =v(i,j)+dt*(neu*((v(i+1,j)-2*v(i,j)+v(i-1,j))*dxi^2 ...

+(v(i,j+1)-2*v(i,j)+v(i,j-1)*dyi^2))-(u_ave*((v(i+1,j)-v(i-1,j))*0.5*dxi)+v(i,j)*((v(i,j+1)-v(i,j-1))*0.5*dyi)));

end

end

% disp(vp);

%Calculating Right Hand side of Poisson Equation

k=0;

for j=jmin : jmax

for i=imin : imax

k=k+1;

R(k)=-rho /dt*( ( up ( i +1, j )-up( i , j ) )*dxi +(vp( i , j+1)-vp ( i , j ))*dyi ) ;

end

end

%Calculating Pressures

pv=La\(R');

%Converting pv to mesh representation

k=0;

for j=jmin : jmax

for i=imin : imax

k=k+1;

p(i,j)=pv (k);

end

end

%Corrector Step

for j=jmin : jmax

for i=imin+1: imax

u(i , j )=up(i , j)-dt/rho*(p( i , j )-p(i -1, j ) )*dxi ;

end

end

for j=jmin+1: jmax

for i=imin : imax

v( i , j )=vp( i , j )-dt/rho*(p( i , j )-p( i , j -1))*dyi ;

end

end

end

filename = 'u_vel.xlsx';

writematrix(u,filename,'Sheet',1,'Range','A1');

filename2 = 'v_vel.xlsx';

writematrix(v,filename2,'Sheet',1,'Range','A1');

Quick answer: Add set(hS,'Color',[0 0.4470 0.7410]) to code line 329

Explanation: Function corrplot uses functions plotmatrix and lsline. In lsline get(hh(k),'Color') is called in for cycle for each line and scatter object in axes. Inside the corrplot it is also called for all axes, which is slow. However, when you first set the color to any given value, internal optimization makes it much faster. I chose [0 0.4470 0.7410], because it is a default color for plotmatrix and corrplot and this setting doesn't change a behavior of corrplot.

Suggestion for a better solution: Add the line of code set(hS,'Color',[0 0.4470 0.7410]) to the function plotmatrix. This will make not only corrplot faster, but also any other possible combinations of plotmatrix and get functions called like this:

h = plotmatrix(A);

% set(h,'Color',[0 0.4470 0.7410])

for k = 1:length(h(:))

get(h(k),'Color');

end

I keep getting this error message when trying to run my code, I'm confident my wiring is correct and I do not know what this error means-

Library 'Servo' is not uploaded to the board. Clear the current Arduino object and recreate it to include the appropriate library. For a list of available libraries, type 'listArduinoLibraries'.

here is my code

a=arduino();

s1 = servo(a, 'D9', 'MinPulseDuration', 700*10^-6, 'MaxPulseDuration', 2300*10^-6);

writePosition(s1,0);

userResponse = "yes";

while userResponse == "yes"

chicken = input("Insert your resistor");

voltage = readVoltage(a, "A0");

if voltage < 1.67155

resistor = "47k";

writePosition(s1,0.25);

minR = 47000 * 0.95;

maxR = 47000 * 1.05;

elseif voltage < 3.53128

resistor = "10k";

writePosition(s1,0.5);

minR = 10000 * 0.95;

maxR = 10000 * 1.05;

elseif voltage < 4.69941

resistor = "1k";

writePosition(s1,0.75);

minR = 1000 * 0.95;

maxR = 1000 * 1.05;

else

resistor = "330";

writePosition(s1,1);

minR = 330 * 0.95;

maxR = 330 * 1.05;

end

resistance = voltageToResistance(voltage);

withinTolerance = (resistance >= minR && resistance <= maxR);

disp(resistor)

if withinTolerance == 1

writeDigitalPin(a, "D4", 1);

writeDigitalPin(a, "D5", 0);

%disp("green")

else

writeDigitalPin(a, "D4", 0);

writeDigitalPin(a, "D5", 1);

%disp("Red")

end

userResponse = input("Would you like to check another resistor? ","s");

writePosition(s1,0);

writeDigitalPin(a, "D4", 0);

writeDigitalPin(a, "D5", 0);

end

The MATLAB AI Chat Playground is now open to the whole community! Answer questions, write first draft MATLAB code, and generate examples of common functions with natural language.

The playground features a chat panel next to a lightweight MATLAB code editor. Use the chat panel to enter natural language prompts to return explanations and code. You can keep chatting with the AI to refine the results or make changes to the output.

Give it a try, provide feedback on the output, and check back often as we make improvements to the model and overall experience.

Looking for an opportunity to practice your AI skills on a real-world problem? Interested in AI for climage change? Sign up for the Kelp Wanted challenge, which tasks participants with developing an algorithm that can detect the presence of kelp forests from satellite images.

Participants of all skill levels from anywhere in the world are welcome to compete!

MathWorks provides the following resources for all participants:

Hello,

What is the difference between a moving angle and a normal angle?

Compute the Rotation about Y-axis over moving angle a = 30°

then

rotation about X-axis of angle β= 45°

What will the code like?

Thank you

Hello there, I have a Amesim Black box model in Simulink. On my desktop, it works well. Also i tried to run on other desktops. Most of them work well. But some of them gives following error: Error in 'Model' while executing C MEX S-function 'Model', (mdlInitializeConditions), at time 0.0. Caused by: in Simcenter Amesim mexfunction: 'Model', Simcenter Amesim fatal error Cannot initialize Simcenter Amesim Model. EXIT This is an urgent case for me. Could you please help me?

Thank you so much.

Write a matlab script that will print the odd numbers, 1 through 20, in reverse.

I cannot figure out how to do this correctly, please help.

Dear Community,

I am trying to perform PowerGUI Loadflow analysis for EV Charging station. The model converges but the load flow vaues on the DC bus is zero. Whether power_loadflow supports Mixed AC/DC load Flow.

Can someone help me by providing guidance on how to preform the same

Regards

Vara

we have extracted a .xml file from solidworks to import in matlab, when we tried to import it shows that simscape multibody should be installed and when we tried to install it it shows the message attached below.

we are working on an educational license provided by our university, is it the issue?

It is crucial to understand that this expression could be used in problems related to engineering, physics, mathematics, or any other aspect of real life.

Typically, Matlab is used to solve PDE and ODE problems. Perhaps users calculated this term 0^0 incorrectly in the process.

>> % Reviewed by Bewar Yousif Ali

>> % How to fix this problem 0^0 in Matlab !?

>> % Mathematically, x^0=1 if x≠0 is equal 1 else undefined(NaN)

>> 0^0

ans =

1

>> f=@(x,y) x^y;

>> f(0,0)

ans =

1

>> v=[2 0 5 -1];

>> v.^0

ans =

1 1 1 1

What amazing animations can be created with no more than 2000 characters of MATLAB code? Check out our GALLERY from the MATLAB Flipbook Mini Hack contest.

Vote on your favorite animations before Dec. 3rd. We will give out MATLAB T-shirts to 10 lucky voters!

Tips: the more you vote, the higher your chance to win.

i=dsolve('Dy=-8*y+40*sin(8*t)','y(0)=5')

Warning: Support for character vector or string inputs will be

removed in a future release. Instead, use syms to declare

variables and replace inputs such as dsolve('Dy = -3*y') with syms

y(t); dsolve(diff(y,t) == -3*y). > In dsolve (line 126)

% Given data

x = [2.0, 3.0, 6.5, 8.0, 12, 15];

f = [14, 20, 17, 16, 23, 125];

% Construct the cubic spline

h = diff(x);

A = zeros(length(x)-2);

for i = 1:length(x)-2

A(i,i) = 2*h(i) + 2*h(i+1);

A(i,i+1) = h(i+1);

A(i+1,i) = h(i);

A(i+1,i+1) = 2*h(i) + h(i+1);

end

b = [6*(f(2)-f(1))/h(1) + 6*(f(3)-f(2))/h(2);

6*(f(4)-f(3))/h(3) + 6*(f(5)-f(4))/h(4)];

M = A\b;

% Evaluate the second derivative at data points

d2f_dx2 = zeros(length(x),1);

for i = 1:length(x)-2

d2f_dx2(i) = M(i);

d2f_dx2(i+1) = M(i) + h(i)*M(i+1);

d2f_dx2(i+2) = M(i) + 2*h(i)*M(i+1) + h(i)*h(i)*M(i+2);

end

% Display second derivatives at data points

disp('Second Derivatives at Data Points:');

disp(d2f_dx2);

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback Error while evaluating Button PrivateButtonPushedFcn.

help to solve this error in face recognition GUI