# Matlab Definition and 304 Discussions

MATLAB (an abbreviation of "matrix laboratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages.
Although MATLAB is intended primarily for numeric computing, an optional toolbox uses the MuPAD symbolic engine allowing access to symbolic computing abilities. An additional package, Simulink, adds graphical multi-domain simulation and model-based design for dynamic and embedded systems.
As of 2020, MATLAB has more than 4 million users worldwide. MATLAB users come from various backgrounds of engineering, science, and economics.

View More On Wikipedia.org
1. ### MATLAB Closed form not the same as the discrete form

clear; lambda = 3e-2; x = 4 * pi/lambda * linspace(eps, 15, 100000); T = 5e-3; t = [0:0.001e-3:T] ; % 0.1:1e-3:0.1+T]; u = 3; a = 4*pi/lambda * u; for i = 1:length(x) Z(i) = sum(-((cos(a.*t) - cos(x(i).*t)).^2 + (sin(a.*t) - sin(x(i).*t)).^2)); end % Z1 = csc((a+x)/2) .*...
2. ### Calculate Conductivity Temperature Dependence in Semiconductors

I have to plot the conductivity dependence of temperature and I have problems with obtaining the right dependency of \mu and n. But let's focus only on carrier concentration first. For n I used the third equation. From what I understand N_D is a constant. I want my plot to look like this: But...
3. ### Extraction Flash Calculation - 4 Component and 2 Phase System

I am performing extraction flash calculations for 4 component and 2 phase system. For anyone somewhat shaky with what extraction flash calculation is; extraction is performed, feed composition is known and we are calculating compositions of both phases at equilibrium, mole fraction of every...
4. ### Engineering How do I use Simulink to create a control system with a 2nd order ODE?

Equation: , where matrix D, C, G and F can be represented by I'm supposed to design a control system that looks like this: I am given that the dynamic model = fcn(D,C,G,dq) where the dq is the same as 𝑞̇ and d2q in the diagram is the same 𝑞̈. The default initial value of [𝑞(0), 𝑞̇(0)] is...
5. ### Comp Sci Populating a 1001x101 2D array in MATLAB

The method I employed was based on a nested loop. I ran into two issues with this approach 1. The code took way too long to run, easily going for over 7 minutes. 2. In the end, it didn't even completely work, due to the "index exceeding the array length". This confuses me For the relevant...
6. ### Using 2 MATLAB files to simulate 3 plots

First of all, I'm an absolute beginner in MATLAB. Secondly, I have 2 MATLAB files, one entitled as a "main file" and the other one as a helping .m file, which is called by the main file. I need to run the main file in order to obtain 3 plots. What is the exact procedure that I should follow in...
7. ### Conversion from Mathematica to Matlab

Hello!. I am new to the forum and I am also a newbie to programming. I want to convert a Mathematica code to Matlab, but I don't understand how to translate these lines. This code is Mathematica 5.0. defvar := Module[{a}, Clear[ cN, cNf, ginix ]; Clear[ Nh, Nhf, gini ]; cN =...
8. ### Problem calculating eigenvalues and eigenvectors

Hello everyone. I am trying to construct a functioning version of randomfields (specifically 2D_karhunen_loeve_identification_example.py) in Matlab. For that, I have to calculate the Karhunen-Loève expansion of 2D data, since this is what it says in the documentation. I also have some sample...
9. ### MATLAB Transforming long symbolic expressions to use in matlab ode45?

hi guys i build a little function that outputs a symbolic expression like that below, this is only a part of it: (105*(x(5)^2/r^2 - 1)^2)/8 + (210*x(5)^2*(x(5)^2/r^2 - 1))/r^2))/(r^2)^(9/2) + (8*R^7*u*x(5) the problem is the only way to integrate this output is to expand the function externally...
10. ### ODE solver for second Order ODE with Stiffness and Mass Matrices

i am new to matlab and and as shown below I have a second order differential equation M*u''+K*u=F(t) where M is the mass matrix and K is the stifness matrix and u is the displacement. and i have to write a code for matlab using ODE45 to get a solution for u. there was not so much information on...
11. ### MATLAB Can I calculate the covariance matrix of a large set of data?

Hello everyone. I want to calculate the covariance matrix of a stochastic process using Matlab as cov(listOfUVValues) being the dimensions of listOfUVValues 211302*50. I get the following error: Requested 211302x211302 (332.7GB) array exceeds maximum array size preference. Creation of...
12. ### MATLAB Creating and recovering a frequency shift in time domain in MATLAB

I am trying to simulate and process the Doppler signals. My main problem is a little more complex so I am only posting a simple version of it. Task1: I have a time-domain signal with the velocity of the target as mu. I need to change the velocity to mu cos(theta) where theta is a vector from 0...
13. ### A Has anybody programmed the mcKL expansion?

Hello everyone. I am trying to implement the mcKL expansion proposed in this article using Matlab and two vectors of correlated data of size 1000*50, meaning 50 realizations of two random processes measured 1000 times. As the article says, if two stochastic processes are correlated, one cannot...
14. ### MATLAB How can I plot a Hohmann Transfer Orbit in MATLAB using ode45?

function Asteroid_Mining clc %Initial conditions g0 = 9.81; %gravity (m/s^2) p = 1.225; %atmospheric density at sea level (kg/m3) Re = 6378; %radius of Earth (km) Ra = 7.431e7; %distance of Bennu from Earth in (km) [August 2023] G = 6.674e-11/1e9; % Gravitational constant (km3/kg.s2) mu =...
15. ### MATLAB Calculating the time taken for an asteroid mission using MATLAB

Using MATLAB, I am trying to calculate the time taken for a spacecraft to travel from Earth to a near earth asteroid and then returning back to Earth but so far I have had no luck. Furthermore, I want to plot a Hohmann transfer and calculate the mass of fuel required for this mission. If...
16. ### MATLAB MATLAB Plug flow reactor optimisation Problem

The assignment is to find the optimal operating temperature and maximum product concentration of reactant B, assuming a constant temperature across the PFR length. Please could someone help? thanks the reaction is a series reaction: A → B → C (liquid phase) Here is my current code which is...
17. ### MATLAB How to change the frequency values inside a time domain signal phase

The problem I am having is simple. I have a Gaussian spectrum initially. Like this, Process 1: S = m0/sqrt(2*pi*sigma^2) * exp(-(vel_axis - mu).^2/(2*sigma^2)); Here, mu is the mean velocity (frequency) and sigma is the standard deviation. vel_axis is the axis on which I am calculating this...
18. ### Tetrahedron Simplex Shape Functions in FEA

Hi, 2 part question trying to get tetrahedron Finite Element shape functions working: 1) How do I properly setup the shape coefficient matrix and 2) How do I build the coefficient quantities in the shape functions properly? ANY tips or corrections may unblock me and would be of much value...
19. ### Non linear BVP using a shooting algoritm with MATLAB?

hi guys i was trying to use this shooting algorithm from Xue and Chen Scientific Computing with MATLAB book : to solve this non linear temperature distribution problem : i checked my Matlab function multiple times but i am keep getting a nonsense graph for the temperature , can someone cheak...
20. ### Comp Sci Matlab report help please (Finite Difference Method)

We have to submit a Matlab (my worst module) assignment to show the heat transfer on a plate. However, I have the 2 codes almost done but I am struggling to write the report. To calculate the temperature on a 2D aluminum plate we need to use the Explicit Finite Difference Method. The problem...
21. ### Temperature distribution of a current carrying wire using the Shooting method in Matlab

hi guys i was trying to solve this non linear ode using the shooting algorithm in Matlab : i am not sure how to solve it using the normal shooting algorithm i have , since no other boundary at x = L/2 was given to check the shooting ?! function dTdx = bar_temp(x,y) k = 72; h = 2000; epsilon =...

23. ### MATLAB How to make a while loop stop when reaching a certain value [Solved]

m_1 = 1; C_p1 = 2219; T_1in = 100 + 273.15; T_1out = 75 + 273.15; Q_1 = (m_1)*C_p1*(T_1in-T_1out); while Q_1 ~= 30000 T_1outnew = T_1out + 0.1; Q_1 = (m_1)*C_p1*(T_1in-T_1outnew); T_1out = T_1outnew; end T_1outnew keeps increasing, but the code never stops; and naturally, Q...
24. ### A Nonlinear Wave Equation (Nonlinear Helmholtz)

I am trying to solve a PDE (which I believe can be approximated as an ODE). I have tried to solve it using 4th Order Runge-Kutta in MATLAB, but have struggled with convergence, even at an extremely high number of steps (N=100,000,000). The PDE is: \frac{\partial^2 E(z)}{\partial z^2} +...
25. ### Widgets for Visualizing Engineering

Hi! First off, I'm just an upcoming junior in Civil Engineering, and I have little teaching experience. I have done well in engineering classes so far though, and I've thought about ways to improve how classes are taught. While there are some widgets for engineering, like those in MATHTAB and...
26. ### MATLAB Deconvolving two signals with different sampling rates

Hi, So i am in a fix now. I have a discrete time signal which is produced by a device with Nyquist frequency as 50MHz and 1088 samples (there is nothing i can do with the device to change the frequency or number of samples). I have an analytical signal which is produced in the frequency domain...
27. ### A Writing a matlab program to solve the Kepler Problem (Universal Vars)

Introduction: I am writing a Matlab program that solves the Kepler problem for any Elliptical, Hyperbolic, or Circular orbit. Given an initial position vector, velocity vector, find the position vector and velocity vector after some given time. I am not doing this for any class, I have been...
28. ### How can I create an equation in matlab for image processing?

Here is the documentation for the 2DFFT: https://www.mathworks.com/help/matlab/ref/fft2.html how would I go about creating this formula on matlab to apply it on an image? My guess is that I need to create the equation and then multiply it to the image I need such as: $$U = VI$$ where V is my...
29. ### The modeling and design of a photoreactor for phenol degradation in wastewater treatment using MATLAB

I researched the solar collectors implemented in practice for water detoxification and I found out that the preferred design is the Compound Parabolic Concentrator. Knowing that I have no information regarding radiation beyond what's taught generally in heat transfer courses in chemical...
30. ### Modeling/Analysis of optical fibers

Hello PF, I need some guide points to help me formulate a project idea on the topic of optical fibers. Namely, the professor suggested I should look for topics on modeling of optical fibers, analysis of different optical fibers, characteristics etc. and to work in a simulator, or perform a...
31. ### Position-Velocity phase plane portrait in MATLAB?

For example, how would I graph a Position-Velocity phase portrait of a nodal sink or spiral sink? Given form of mx'' = -cx' - kx + βx^3.
32. ### Mathematical Modeling of an evaporator for evaporating water

I am trying to model an evaporator which evaporates water to steam in Matlab/simulink. Are there any governing equations i need to know and follow when modelling the evaporator mathematically? Please let me know.
33. ### Engineering Reconstruct a signal by determining the N Fourier Coefficients

%My code: %Type of signal: square T = 40; %Period of the signal [s] F=1/T; % fr D = 23; % length of signal(duration) dt=(D/T)*100; N = 50; %Number of coefficients w0 = 2*pi/T; %signal pulse t1= 0:0.002:T; % original signal sampling x1 = square((2*pi*F)*(t1),dt);%initial square signal...
34. ### MATLAB Bilinear spline interpolation MATLAB using MESHGRID and SURF

Hello. So, I must provide a solution for an image processing course I am taking (implemented in MATLAB). The task is as follows: 1. I must provide a MATLAB script that takes in a DISCRETE N x N matrix (Greyscale picture) and does Bilinear spline interpolation on it. This is the spline...
35. ### Anyone using Maple in 2019 on regular basis?

I know these software packages were discussed a lot in the past, but I have not seen much input from the last couple years. I have used Matlab for many years, but remember using Maple in University Physics courses many years ago. I'm interested in a software package for symbolic math to use...
36. ### Finding the diameter of a wire

Mentor node: Added code tags From=menu('select:','c', 'g', 'a', 's:'); This is part of my code and I'm not coming up with anything close l=input('input wire length') %current copper=12.5572...
37. ### What specs should I look for in a laptop

After completing my sophomore year at college as a Physics major and I realized that the laptop I currently have is not able to keep up with the demand I put it under for school. The laptop I currently have has a <2 hour battery life and has been known to crap out (didn't know how else to...
38. ### I Calculate the exit force of a bullet leaving the barrel

So, Basic premise is I have 1 input and one output, Energy friom the gunpower burning is input, and the output is the force which pushes the bullet after it is reduced by the friction. m = 12.96 g s = 0.6985 m (barrel lenght) E = 6734 J k = 0.5 (friction coeffcient) I am sorry for lack of...
39. ### MATLAB Spring mass impact system in Matlab - How to correct it?

I am new to Simulink and I wanted to start practicing using a spring mass damper system. My first tutorial was this: Later, I wanted to model a spring system where a mass moving at a known velocity hits the spring. The governing equation and a similar modeling method given in the previous...
40. ### Non trivial solution to Schrödinger equation for 1-D infinite well

Hello, I am trying to find the solution of Schrödinger equation on matlab. However, when I apply boundary conditions, MATLAB only gives me the solution with both coefficients 0. I want to find the solution : Asin(n*pi*x/L) You can see my code below. Could you please tell me where is my mistake...
41. ### I Simulating irrational numbers

I am trying to write an algorithm that generates two random numbers in a given interval such that their ratio is an irrational number. I understand that all numbers stored on a computer are rational, so it is not possible to have a truly irrational number in a simulation. So, instead I am...
42. ### I Re-scaling of exponentially distributed numbers

For simplicity, let ##N=1##. The following histograms show my results. The generated random numbers are initially exponentially distributed. But after re-scaling they become almost uniformly distributed. What is the cause of that, and is there a solution? P.S. Here is my code in Matlab...
43. ### Need help with Matlab Function of Differential Equations

WHAT HAPPENS IS That I need to model the example of A Protein G example, using a function f in Matlab, but when I execute the script, the graphics I get do not correspond to those of the example. The problem is that I can not understand what the model seeks to represent, besides that I do not...
44. ### MATLAB MATLAB degrades image quality

There is an original image test1.jpg. The problem is to show axes in the image and retain image quality. I am running the following code: img = imread('test1.jpg'); % define variables imgsize1 = size(img,1); % size on screen imgsize2 = size(img,2); xreal = 1; % meter yreal = 1; %...
45. ### MATLAB How to transform a plot to use a logarithmic scale?

I wrote the following code in MATLAB: t = [0:0.001:0.1]; noise = randn(1,size(t,2)); a = 15*10^9; b = 15*10^(-3); c = 7*10^8; y = a*exp(-t/b)+c+noise*100000000; fun = @(p,t)p(1)*exp(-t/p(2))+p(3); p0 = [15.5*10^9, 14*10^(-3), 6*10^8]; p = lsqcurvefit(fun, p0, t, y); t_fit = [0:0.0001:0.1]; y_fit...
46. ### MATLAB Why is this Java code not working?

Hello all: I am reading a comutacomputa physics book and trying a code from it in MATLAB it is not working and due to my lack of knowledge in this field I can't see where is the mistake hope you can take a look import java.lang .*; public class Motion { static final int n = 100000, j =...
47. ### MATLAB_Quantum Well_Finite Difference Method

Homework Statement Hi, I am new to MATLAB and have an assignment where I have to construct a Hamiltonian matrix, apply boundary conditions, then find corresponding eigenvalues and eigenvectors for the electron in a box problem. I am stumped where to start. From our class we learned that you...
48. ### Large datasets - how to handle / alternatives

Hello, I am trying to do the following: I have two inputs that are very large files - I extract the first column of each so I have two vectors of ~2-5mil by 1. This is timing information. The goal is to extract the indices of each vector where the time in one vector is within a certain...
49. ### MATLAB To what extent is the fit to experimental data good?

I have experimental spectrum in which y-axis is intensity values, and x-axis is frequency values. Int - array of experimental intensities (y-axis). w - array of frequencies (x-axis). I know the view of theoretical function that must describe the obtained spectrum. I explicitly set the function...
50. ### Python How to remove attenuation

Dear Sirs, I have a signal which has an attenuation of 20dB per decade, how do I remove this attenuation using SCIPY? Alternatively how to do it in MATLAB if there are no SCIPY users here? I'm a SCIPY/MATLAB novice fyg. Thank you for your kind assistance Abim