ans =

**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

# Updated Discussions

This project discusses predator-prey system, particularly the Lotka-Volterra equations,which model the interaction between two sprecies: prey and predators. Let's solve the Lotka-Volterra equations numerically and visualize the results.% Define parameters

% Define parameters

alpha = 1.0; % Prey birth rate

beta = 0.1; % Predator success rate

gamma = 1.5; % Predator death rate

delta = 0.075; % Predator reproduction rate

% Define the symbolic variables

syms R W

% Define the equations

eq1 = alpha * R - beta * R * W == 0;

eq2 = delta * R * W - gamma * W == 0;

% Solve the equations

equilibriumPoints = solve([eq1, eq2], [R, W]);

% Extract the equilibrium point values

Req = double(equilibriumPoints.R);

Weq = double(equilibriumPoints.W);

% Display the equilibrium points

equilibriumPointsValues = [Req, Weq]

% Solve the differential equations using ode45

lotkaVolterra = @(t,Y)[alpha*Y(1)-beta*Y(1)*Y(2);

delta*Y(1)*Y(2)-gamma*Y(2)];

% Initial conditions

R0 = 40;

W0 = 9;

Y0 = [R0, W0];

tspan = [0, 100];

% Solve the differential equations

[t, Y] = ode45(lotkaVolterra, tspan, Y0);

% Extract the populations

R = Y(:, 1);

W = Y(:, 2);

% Plot the results

figure;

subplot(2,1,1);

plot(t, R, 'r', 'LineWidth', 1.5);

hold on;

plot(t, W, 'b', 'LineWidth', 1.5);

xlabel('Time (months)');

ylabel('Population');

legend('R', 'W');

grid on;

subplot(2,1,2);

plot(R, W, 'k', 'LineWidth', 1.5);

xlabel('R');

ylabel('W');

grid on;

hold on;

plot(Req, Weq, 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r');

legend('Phase Trajectory', 'Equilibrium Point');

Now, we need to handle a modified version of the Lotka-Volterra equations. These modified equations incorporate logistic growth fot the prey population.

These equations are:

% Define parameters

alpha = 1.0;

K = 100; % Carrying Capacity of the prey population

beta = 0.1;

gamma = 1.5;

delta = 0.075;

% Define the symbolic variables

syms R W

% Define the equations

eq1 = alpha*R*(1 - R/K) - beta*R*W == 0;

eq2 = delta*R*W - gamma*W == 0;

% Solve the equations

equilibriumPoints = solve([eq1, eq2], [R, W]);

% Extract the equilibrium point values

Req = double(equilibriumPoints.R);

Weq = double(equilibriumPoints.W);

% Display the equilibrium points

equilibriumPointsValues = [Req, Weq]

% Solve the differential equations using ode45

modified_lv = @(t,Y)[alpha*Y(1)*(1-Y(1)/K)-beta*Y(1)*Y(2);

delta*Y(1)*Y(2)-gamma*Y(2)];

% Initial conditions

R0 = 40;

W0 = 9;

Y0 = [R0, W0];

tspan = [0, 100];

% Solve the differential equations

[t, Y] = ode45(modified_lv, tspan, Y0);

% Extract the populations

R = Y(:, 1);

W = Y(:, 2);

% Plot the results

figure;

subplot(2,1,1);

plot(t, R, 'r', 'LineWidth', 1.5);

hold on;

plot(t, W, 'b', 'LineWidth', 1.5);

xlabel('Time (months)');

ylabel('Population');

legend('R', 'W');

grid on;

subplot(2,1,2);

plot(R, W, 'k', 'LineWidth', 1.5);

xlabel('R');

ylabel('W');

grid on;

hold on;

plot(Req, Weq, 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r');

legend('Phase Trajectory', 'Equilibrium Point');

Hello, everyone! I’m Mark Hayworth, but you might know me better in the community as Image Analyst. I've been using MATLAB since 2006 (18 years). My background spans a rich career as a former senior scientist and inventor at The Procter & Gamble Company (HQ in Cincinnati). I hold both master’s & Ph.D. degrees in optical sciences from the College of Optical Sciences at the University of Arizona, specializing in imaging, image processing, and image analysis. I have 40+ years of military, academic, and industrial experience with image analysis programming and algorithm development. I have experience designing custom light booths and other imaging systems. I also work with color and monochrome imaging, video analysis, thermal, ultraviolet, hyperspectral, CT, MRI, radiography, profilometry, microscopy, NIR, and Raman spectroscopy, etc. on a huge variety of subjects.

I'm thrilled to participate in MATLAB Central's Ask Me Anything (AMA) session, a fantastic platform for knowledge sharing and community engagement. Following Adam Danz’s insightful AMA on staff contributors in the Answers forum, I’d like to discuss topics in the area of image analysis and processing. I invite you to ask me anything related to this field, whether you're seeking recommendations on tools, looking for tips and tricks, my background, or career development advice. Additionally, I'm more than willing to share insights from my experiences in the MATLAB Answers community, File Exchange, and my role as a member of the Community Advisory Board. If you have questions related to your specific images or your custom MATLAB code though, I'll invite you to ask those in the Answers forum. It's a more appropriate forum for those kinds of questions, plus you can get the benefit of other experts offering their solutions in addition to me.

For the coming weeks, I'll be here to engage with your questions and help shed light on any topics you're curious about.

Does your company or organization require that all your Word Documents and Excel workbooks be labeled with a Microsoft Azure Information Protection label or else they can't be saved? There are the labels that are right below the tool ribbon that apply a category label such as "Public", "Business Use", or "Highly Restricted". If so, you can either

- Create and save a "template file" with the desired label and then call copyfile to make a copy of that file and then write your results to the new copy, or
- If using Windows you can create and/or open the file using ActiveX and then apply the desired label from your program's code.

For #1 you can do

copyfile(templateFileName, newDataFileName);

writematrix(myData, newDataFileName);

If the template has the AIP label applied to it, then the copy will also inherit the same label.

For #2, here is a demo for how to apply the code using ActiveX.

% Test to set the Microsoft Azure Information Protection label on an Excel workbook.

% Reference support article:

% https://www.mathworks.com/matlabcentral/answers/1901140-why-does-azure-information-protection-popup-pause-the-matlab-script-when-i-use-actxserver?s_tid=ta_ans_results

clc; % Clear the command window.

close all; % Close all figures (except those of imtool.)

clear; % Erase all existing variables. Or clearvars if you want.

workspace; % Make sure the workspace panel is showing.

format compact;

% Define your workbook file name.

excelFullFileName = fullfile(pwd, '\testAIP.xlsx');

% Make sure it exists. Open Excel as an ActiveX server if it does.

if isfile(excelFullFileName)

% If the workbook exists, launch Excel as an ActiveX server.

Excel = actxserver('Excel.Application');

Excel.visible = true; % Make the server visible.

fprintf('Excel opened successfully.\n');

fprintf('Your workbook file exists:\n"%s".\nAbout to try to open it.\n', excelFullFileName);

% Open up the existing workbook named in the variable fullFileName.

Excel.Workbooks.Open(excelFullFileName);

fprintf('Excel opened file successfully.\n');

else

% File does not exist. Alert the user.

warningMessage = sprintf('File does not exist:\n\n"%s"\n', excelFullFileName);

fprintf('%s\n', warningMessage);

errordlg(warningMessage);

return;

end

% If we get here, the workbook file exists and has been opened by Excel.

% Ask Excel for the Microsoft Azure Information Protection (AIP) label of the workbook we just opened.

label = Excel.ActiveWorkbook.SensitivityLabel.GetLabel

% See if there is a label already. If not, these will be null:

existingLabelID = label.LabelId

existingLabelName = label.LabelName

% Create a label.

label = Excel.ActiveWorkbook.SensitivityLabel.CreateLabelInfo

label.LabelId = "a518e53f-798e-43aa-978d-c3fda1f3a682";

label.LabelName = "Business Use";

% Assign the label to the workbook.

fprintf('Setting Microsoft Azure Information Protection to "Business Use", GUID of a518e53f-798e-43aa-978d-c3fda1f3a682\n');

Excel.ActiveWorkbook.SensitivityLabel.SetLabel(label, label);

% Save this workbook with the new AIP setting we just created.

Excel.ActiveWorkbook.Save;

% Shut down Excel.

Excel.ActiveWorkbook.Close;

Excel.Quit;

% Excel is now closed down. Delete the variable from the MATLAB workspace.

clear Excel;

% Now check to see if the AIP label has been set

% by opening up the file in Excel and looking at the AIP banner.

winopen(excelFullFileName)

Note that there is a line in there that gets an AIP label from the existing workbook, if there is one at all. If there is not one, you can set one. But to determine what the proper LabelId (that crazy long hexadecimal number) should be, you will probably need to open an existing document that already has the label that you want set (applied to it) and read that label.

Swimming, diving

21%

Other water-based sport

5%

Gymnastics

20%

Other indoor arena sport

19%

track, field

15%

Other outdoor sport

21%

86 votes

This stems purely from some play on my part. Suppose I asked you to work with the sequence formed as 2*n*F_n + 1, where F_n is the n'th Fibonacci number? Part of me would not be surprised to find there is nothing simple we could do. But, then it costs nothing to try, to see where MATLAB can take me in an explorative sense.

n = sym(0:100).';

Fn = fibonacci(n);

Sn = 2*n.*Fn + 1;

Sn(1:10) % A few elements

For kicks, I tried asking ChatGPT. Giving it nothing more than the first 20 members of thse sequence as integers, it decided this is a Perrin sequence, and gave me a recurrence relation, but one that is in fact incorrect. Good effort from the Ai, but a fail in the end.

Is there anything I can do? Try null! (Look carefully at the array generated by Toeplitz. It is at least a pretty way to generate the matrix I needed.)

X = toeplitz(Sn,[1,zeros(1,4)]);

rank(X(5:end,:))

Hmm. So there is no linear combination of those columns that yields all zeros, since the resulting matrix was full rank.

X = toeplitz(Sn,[1,zeros(1,5)]);

rank(X(6:end,:))

But if I take it one step further, we see the above matrix is now rank deficient. What does that tell me? It says there is some simple linear combination of the columns of X(6:end,:) that always yields zero. The previous test tells me there is no shorter constant coefficient recurrence releation, using fewer terms.

null(X(6:end,:))

Let me explain what those coefficients tell me. In fact, they yield a very nice recurrence relation for the sequence S_n, not unlike the original Fibonacci sequence it was based upon.

S(n+1) = 3*S(n) - S_(n-1) - 3*S(n-2) + S(n-3) + S(n-4)

where the first 5 members of that sequence are given as [1 3 5 13 25]. So a 6 term linear constant coefficient recurrence relation. If it reminds you of the generating relation for the Fibonacci sequence, that is good, because it should. (Remember I started the sequence at n==0, IF you decide to test it out.) We can test it out, like this:

SfunM = memoize(@(N) Sfun(N));

SfunM(25)

2*25*fibonacci(sym(25)) + 1

And indeed, it works as expected.

function Sn = Sfun(n)

switch n

case 0

Sn = 1;

case 1

Sn = 3;

case 2

Sn = 5;

case 3

Sn = 13;

case 4

Sn = 25;

otherwise

Sn = Sfun(n-5) + Sfun(n-4) - 3*Sfun(n-3) - Sfun(n-2) +3*Sfun(n-1);

end

end

A beauty of this, is I started from nothing but a sequence of integers, derived from an expression where I had no rational expectation of finding a formula, and out drops something pretty. I might call this explorational mathematics.

The next step of course is to go in the other direction. That is, given the derived recurrence relation, if I substitute the formula for S_n in terms of the Fibonacci numbers, can I prove it is valid in general? (Yes.) After all, without some proof, it may fail for n larger than 100. (I'm not sure how much I can cram into a single discussion, so I'll stop at this point for now. If I see interest in the ideas here, I can proceed further. For example, what was I doing with that sequence in the first place? And of course, can I prove the relation is valid? Can I do so using MATLAB?)

(I'll be honest, starting from scratch, I'm not sure it would have been obvious to find that relation, so null was hugely useful here.)

Similar to what has happened with the wishlist threads (#1 #2 #3 #4 #5), the "what frustrates you about MATLAB" thread has become very large. This makes navigation difficult and increases page load times.

So here is the follow-up page.

What should you post where?

Next Gen threads (#1): features that would break compatibility with previous versions, but would be nice to have

@anyone posting a new thread when the last one gets too large (about 50 answers seems a reasonable limit per thread), please update this list in all last threads. (if you don't have editing privileges, just post a comment asking someone to do the edit)

Hi everyone,

I've recently joined a forest protection team in Greece, where we use drones for various tasks. This has sparked my interest in drone programming, and I'd like to learn more about it. Can anyone recommend any beginner-friendly courses or programs that teach drone programming?

I'm particularly interested in courses that focus on practical applications and might align with the work we do in forest protection. Any suggestions or guidance would be greatly appreciated!

Thank you!

What should you post where?

Next Gen threads (#1): features that would break compatibility with previous versions, but would be nice to have

@anyone posting a new thread when the last one gets too large (about 50 answers seems a reasonable limit per thread), please update this list in all last threads. (if you don't have editing privileges, just post a comment asking someone to do the edit)

This topic is for features you would like to see for the MATLAB Answers facility itself, and also for bug reports about the MATLAB Answers facility.

This topic is the follow on to the first Wish-list for MATLAB Answer sections and second MATLAB Answers Wish-list #2 (and bug reports). Those grew large enough to become unwieldy; and Mathworks has made enough changes to make a number of the past points no longer of relevance. More recently there was the limited purpose New design of the forum - grey on white which turned into a bug and wish list; I have renamed that for continuity.

I suggest one wish (or bug report) per answer, so that people can vote their wishes.

Hello, MATLAB enthusiasts! 🌟

Over the past few weeks, our community has been buzzing with insightful questions, vibrant discussions, and innovative ideas. Whether you're a seasoned expert or a curious beginner, there's something here for everyone to learn and enjoy. Let's take a moment to highlight some of the standout contributions that have sparked interest and inspired many. Dive in and see how you can join the conversation or find solutions to your own challenges!

### Interesting Questions

How can i edit my code which works on r2014b version at work but not on my personal r2024a version? by Oluwadamilola Oke

Oluwadamilola Oke is seeking assistance with a MATLAB code that works on version r2014b but encounters errors on version r2024a. The issue seems to be related to file location or the use of specific commands like movefile. If you have experience with these versions of MATLAB, your expertise could be invaluable.

Yohay has been working on a simulation to measure particle speed and fit it to the Maxwell-Boltzmann distribution. However, the fit isn't aligning perfectly with the data. Yohay has shared the code and histogram data for community members to review and provide suggestions.

Alessandro Livi is toggling between C++ for Arduino Pico and MATLAB App Designer. They suggest an enhancement where typing // for comments in MATLAB automatically converts to %. This small feature could improve the workflow for many users who switch between programming languages.

### Popular Discussions

Athanasios Paraskevopoulos has started an engaging discussion on Gabriel's Horn, a shape with infinite surface area but finite volume. The conversation delves into the mathematical intricacies and integral calculations required to understand this paradoxical shape.

Honzik has brought up an interesting topic about custom fonts for MATLAB. While popular coding fonts handle characters like 0 and O well, they often fail to distinguish between different types of brackets. Honzik suggests that MathWorks could develop a custom font optimized for MATLAB syntax to reduce coding errors.

### From the Blogs

Guy Rouleau addresses a common error in Simulink models: "Derivative of state '1' in block 'X/Y/Integrator' at time 0.55 is not finite." The blog post explores various tools and methods to diagnose and resolve this issue, making it a valuable read for anyone facing similar challenges.

Guest writer Gianluca Carnielli, featured by Adam Danz, shares insights on creating time-sensitive animations using MATLAB. The article covers controlling the motion of multiple animated objects, organizing data with timetables, and simplifying animations with the retime function. This is a must-read for anyone interested in scientific animations.

Feel free to check out these fascinating contributions and join the discussions! Your input and expertise can make a significant difference in our community.

Hello MathWorks Community,

I am excited to announce that I am currently working on a book project centered around Matrix Algebra, specifically designed for MATLAB users. This book aims to cater to undergraduate students in engineering, where Matrix Algebra serves as a foundational element.

Matrix Algebra is not only pivotal in understanding complex engineering concepts but also in applying these principles effectively in various technological solutions. MATLAB, renowned for its powerful computational capabilities, is an excellent tool to explore and implement these concepts, making it a perfect companion for this book.

As I embark on this journey to create a resource that bridges theoretical matrix algebra with practical MATLAB applications, I am looking for one or two knowledgeable individuals who have a firm grasp of both subjects. If you have experience in teaching or applying matrix algebra in engineering contexts and are familiar with MATLAB, your contribution could be invaluable.

Collaborators will help in shaping the content to ensure it is educational, engaging, and technically robust, making complex concepts accessible and applicable for students.

If you are interested in contributing to this project or know someone who might be, please reach out to discuss how we can work together to make this book a valuable resource for engineering students.

Thank you and looking forward to your participation!

function ans = your_fcn_name(n)

n;

j=sum(1:n);

a=zeros(1,j);

for i=1:n

a(1,((sum(1:(i-1))+1)):(sum(1:(i-1))+i))=i.*ones(1,i);

end

disp

Check out the LLMs with MATLAB project on File Exchange to access Large Language Models from MATLAB.

Along with the latest support for GPT-4o mini, you can use LLMs with MATLAB to generate images, categorize data, and provide semantic analyis.

Don't use / What are Projects?

26%

1–10

31%

11–20

16%

21–30

9%

31–50

7%

51+ (comment below)

11%

2943 votes

Gabriel's horn is a shape with the paradoxical property that it has infinite surface area, but a finite volume.

Gabriel’s horn is formed by taking the graph of with the domain and rotating it in three dimensions about the axis.

There is a standard formula for calculating the volume of this shape, for a general function .Wwe will just state that the volume of the solid between a and b is:

The surface area of the solid is given by:

One other thing we need to consider is that we are trying to find the value of these integrals between 1 and ∞. An integral with a limit of infinity is called an improper integral and we can't evaluate it simply by plugging the value infinity into the normal equation for a definite integral. Instead, we must first calculate the definite integral up to some finite limit b and then calculate the limit of the result as b tends to ∞:

Volume

We can calculate the horn's volume using the volume integral above, so

The total volume of this infinitely long trumpet isπ.

Surface Area

To determine the surface area, we first need the function’s derivative:

Now plug it into the surface area formula and we have:

This is an improper integral and it's hard to evaluate, but since in our interval

So, we have :

Now,we evaluate this last integral

So the surface are is infinite.

% Define the function for Gabriel's Horn

gabriels_horn = @(x) 1 ./ x;

% Create a range of x values

x = linspace(1, 40, 4000); % Increase the number of points for better accuracy

y = gabriels_horn(x);

% Create the meshgrid

theta = linspace(0, 2 * pi, 6000); % Increase theta points for a smoother surface

[X, T] = meshgrid(x, theta);

Y = gabriels_horn(X) .* cos(T);

Z = gabriels_horn(X) .* sin(T);

% Plot the surface of Gabriel's Horn

figure('Position', [200, 100, 1200, 900]);

surf(X, Y, Z, 'EdgeColor', 'none', 'FaceAlpha', 0.9);

hold on;

% Plot the central axis

plot3(x, zeros(size(x)), zeros(size(x)), 'r', 'LineWidth', 2);

% Set labels

xlabel('x');

ylabel('y');

zlabel('z');

% Adjust colormap and axis properties

colormap('gray');

shading interp; % Smooth shading

% Adjust the view

view(3);

axis tight;

grid on;

% Add formulas as text annotations

dim1 = [0.4 0.7 0.3 0.2];

annotation('textbox',dim1,'String',{'$$V = \pi \int_{1}^{a} \left( \frac{1}{x} \right)^2 dx = \pi \left( 1 - \frac{1}{a} \right)$$', ...

'', ... % Add an empty line for larger gap

'$$\lim_{a \to \infty} V = \lim_{a \to \infty} \pi \left( 1 - \frac{1}{a} \right) = \pi$$'}, ...

'Interpreter','latex','FontSize',12, 'EdgeColor','none', 'FitBoxToText', 'on');

dim2 = [0.4 0.5 0.3 0.2];

annotation('textbox',dim2,'String',{'$$A = 2\pi \int_{1}^{a} \frac{1}{x} \sqrt{1 + \left( -\frac{1}{x^2} \right)^2} dx > 2\pi \int_{1}^{a} \frac{dx}{x} = 2\pi \ln(a)$$', ...

'', ... % Add an empty line for larger gap

'$$\lim_{a \to \infty} A \geq \lim_{a \to \infty} 2\pi \ln(a) = \infty$$'}, ...

'Interpreter','latex','FontSize',12, 'EdgeColor','none', 'FitBoxToText', 'on');

% Add Gabriel's Horn label

dim3 = [0.3 0.9 0.3 0.1];

annotation('textbox',dim3,'String','Gabriel''s Horn', ...

'Interpreter','latex','FontSize',14, 'EdgeColor','none', 'HorizontalAlignment', 'center');

hold off

daspect([3.5 1 1]) % daspect([x y z])

view(-27, 15)

lightangle(-50,0)

lighting('gouraud')

The properties of this figure were first studied by Italian physicist and mathematician Evangelista Torricelli in the 17th century.

Acknowledgment

I would like to express my sincere gratitude to all those who have supported and inspired me throughout this project.

First and foremost, I would like to thank the mathematician and my esteemed colleague, Stavros Tsalapatis, for inspiring me with the fascinating subject of Gabriel's Horn.

I am also deeply thankful to Mr. @Star Strider for his invaluable assistance in completing the final code.

References:

figure out what my old code does

18%

write code comments for future me

11%

address a code analyzer warning

3%

reflect on the skills I've gained

8%

get food on my mouse and keyboard

37%

All of the above

22%

15659 votes