Quantcast
Channel: MATLAB programming & numeric computing platform
Viewing all 31096 articles
Browse latest View live

Estimating parameters of a nonhomogeneous Poisson process (using Indirect Inference)

$
0
0

Hi guys,

I am trying to estimate the parameters of a nonhomogeneous Poisson process (a Poisson function with a time-varying rate parameter) by using Indirect Inference (a specific version of simulated method of moments). This Poisson process is used to simulate the number of breakdowns. The time-varying Poisson rate parameter mu_t is given by

mu_t = omega_mu + alpha_mu * windspeed_t

where omega_mu and alpha_mu are the parameters that have to be estimated and windspeed_t is the windspeed at time t. After simulating a path for mu, I use the poissrnd function to draw from a Poisson distribution, while fixing the seed for each simulation.

Given that I am using a version of the simulated method of moments I need to evaluate the simulated breakdowns and make sure it is as close as possible to the observed number of breakdowns. For this I use a set of statistics from the observed data:

sample_m = [mean(breakdowns), corr(breakdowns, windspeed)]; 

where I calculate the average number of breakdowns per day and calculate the correlation between the number of breakdowns and the windspeed based on ACTUAL data. These statistics will also be calculated for the simulated breakdowns and the distance between the set of statistics is measured using the MSE. The goal is obviously to minimize this distance by finding the optimal parameters. Now that I have explained the idea behind the estimation, here is my implementation:

theta_windspeed_struct = load('ii-windspeed.mat'); theta_windspeed = theta_windspeed_struct.theta_hat; simmed_windspeed = sim_windspeed(theta_windspeed, T); omega_mu_ini = 0.5; alpha_mu_ini = 0.2; theta_ini = [omega_mu_ini, alpha_mu_ini]; [theta_hat] = fminunc(@(theta) mean((sim_m_breakdowns(theta, T, simmed_windspeed) - sample_m).^2), theta_ini); simulated_mus = sim_breakdowns(theta_hat, T, simmed_windspeed); simulated_m = sim_m_breakdowns(theta_hat, T, simmed_windspeed); 

where T is the size of the simulation and sim_m_breakdowns is given by

function output = sim_m_breakdowns(theta, T, simmed_windspeed) mus = sim_breakdowns(theta, T, simmed_windspeed); rng(1) breakdowns = poissrnd(mus); output = [mean(breakdowns), corr(breakdowns, simmed_windspeed)]; end 

and sim_breakdowns is given by

function output = sim_breakdowns(theta, T, simmed_windspeed) omega_mu = theta(1); alpha_mu = theta(2); mus = zeros(T, 1); for t=1:T mus(t) = omega_mu + (alpha_mu * simmed_windspeed(t)); end output = mus; end 

The problem is that fminunc stops after just one run, claiming that the objective function cannot be decreased along the current search direction (even though the MSE > 0.0001). I used a similar method to estimate the parameters for the windspeed equation and that worked perfectly, with the MSE < 0.0001 after a few hundred iterations. My guess is that this "error" is due to my draw from the poissrnd but I don't know why this doesn't work. I feel like everything I did in my code is valid. Do you guys have any idea?

UPDATE: apparently fminsearch does work and yields me relatively good estimates, however I am still interested in why the choice of minimizer matters in this case.

submitted by /u/Marthijn1812
[link] [comments]

Help tweak a MATLAB GUI?

$
0
0

Hi,

I'm running some experiments where participants respond to a visual cue to grasp or not grasp a force sensor. I have a functioning program to do this, but need some additions so that

  1. there's a pre-cue, like a "get ready to move now" which is followed couple (2-5) sec later by the actual cue (which is already present in my code currently)
  2. I need to pseudorandomize the sequence of grasp and no-grasp conditions

Would any of the MATLAB folks here be willing to work on it? Hourly funding is available to complete this job.

Please post here or send me a PM for details.

submitted by /u/eternalbreath
[link] [comments]

[Tips] Series of MATLAB Tutorials

$
0
0

Hello r/matlab,

I have decided to write some tutorials to share some of the knowledge that I have gained over many years of using MATLAB. I am going to include some basic concepts as well as some tips and tricks that I have picked up. Please let me know if there are particular topics that you think would be interesting.

I wrote my first article on working with MATLAB figure properties and you can find it here:

https://medium.com/@cjdellaporta/figure-properties-in-matlab-f2d45dfa28c6

I will be writing a number more centered on plotting and visualization, so understanding how to change properties on graphic objects seemed like a nice place to start.

Happy coding.

submitted by /u/seegedp
[link] [comments]

Cartesian grid matrix to cylindrical grid matrix?

$
0
0

Let's say I have a three dimensional Cartesian cube described by

 x = 0:.1:1; y = 0:.1:1; z = 0:.1:1; [X,Y,Z] = meshgrid(x,y,z); 

And I have some 3D matrix.

 f = X.^2+Y.^2+Z.^2; 

How can I interpolate and transform this matrix onto a cylindrical grid? To me, it appears some interpolation would have to take place on the Cartesian grid matrix. I understand cylindrical values can be calculated using.

 [theta,rho,z] = cart2pol(X,Y,Z); 

But this really doesn't fully achieve what I'm trying to do.

Also, by not making the Cartesian coordinates span from -.5 to .5, the origin is not at the center of the cube, so perhaps interpolation processes might be more out of line with expected values the further away from 0,0,0? That is unless I can move where the center is located.

EDIT: I think I figured it out, anyone want to check my work?

 clear Nx = 11; Ny = 11; x = linspace(-Nx,Nx,Nx); y = linspace(-Ny,Ny,Ny); [X,Y] = meshgrid(x,y); f = (X.^2+Y.^2).^0.5; R = (X.^2+Y.^2).^.5; T = atan2(Y,X); R = (max(R,[],'all')/Nx)*[0:Nx-1]; T = (max(T,[],'all')/Ny)*[0:Ny-1]; [T,R] = meshgrid(T,R); xi = R.*cos(T); yi = R.*sin(T); F = interp2(X,Y,f,xi,yi); subplot(1,2,1) contourf(X,Y,f) subplot(1,2,2) contourf(T,R,F) 
submitted by /u/Helicon_Amateur
[link] [comments]

Creating Plot Templates

$
0
0

I created a plot where I customized for data visualizations. How would I apply those changes to many plots that I have to create in the future without going back and changing every setting individually again?

submitted by /u/GreenTeaKitKat27
[link] [comments]

Windows 10 system getting stuck on running MATLAB

$
0
0

I am running MATLAB on a windows 10 system. The system is getting stuck (full black screen) on running code in MATLAB. However, this happens only when I am working with a large data. The data in this case involved a 30000*5000 matrix and needs training using SVM (support vector machine) classifier (this was done through a libsvm extension). I tried updating graphics drivers and adjusting power settings but it wasnt successful. Adjusting power settings (for maximum performance) did remove a "driver state error" which was causing the system to restart though. But it is still getting stuck (with black screen). System specs are given below

RAM - 4 GB

OS- Windows 10 Home (64 bit)

Processor- Core i3 7020U 2.3Ghz

MATLAB version - 2020a

submitted by /u/daffodils123
[link] [comments]

DAC (digital to analog converter) in Matlab or simulink?

$
0
0

Hello all,

Is there a DAC block in simulink? I have used the ADC block but now once I’m done with my experiment, I have to convert the signal back to analog. Unfortunately, I couldn’t find a DAC block in simulink. Is there any other way of doing it ? Any help is appreciated.

Thanks

submitted by /u/Francescodepazzi
[link] [comments]

About sharing matlab code, simulink models made using Matlab Home version.

$
0
0

I have a Matlab and Simulink 2019a Home licence, i.e. the one which can basically be used only for personal/hobby stuff, as I understand it. It cannot be used for commercial, educational, research etc. purposes.

Questions - - Can I open source the code/models using this Home version? Because once open sourced, on say github, I no longer have control on whether it will be used on a Home version, student version or professional versions. I dont want to land in any trouble for doing this. - Related to the question above. Is it technically possible for a model made on Home version to open on any other version? - Does Mathworks get to know (through some backend script in Matlab) if a model (or for that matter anything) made in the Home version is opened on the Professional version or vice versa?

submitted by /u/zvckp
[link] [comments]

Advice on learning MATLAB and Control theory together

$
0
0

Hi, I've been meaning to catch up on both my MATLAB and control theory knowledge. (Largely due to a break in learning cause of corona)

My plan is to learn Control first and then try and implement stuff in MATLAB.

Is there a better way to do this or any tips and resources you'd like to share?

submitted by /u/Anon199760
[link] [comments]

Changing the axis component of a graph

$
0
0

Hi everyone, hope you all have a good day.

I have a function that after you gave the input, it gives you a graph that plot a wavelength and the intensity such as:

wavelength vs intensity

wavelength (x axis) is an array made with linspace(30, 300, 10000)

y is the intensity array as shown in the graph.

I want to change the x axis so it show a graph of frequency and intensity instead.

Note that the relation between them is wavelength * frequency = speed of light (3e8 m/s)

So i divided the array with constant speed of light to obtain the frequency. However, after dividing it the array now consists of higher frequency to lower frequency (3e8/30 > 3e8/300)

so i rearrange it using fliplr command. I didnt, change the intensity array, when i tried to plot it, i got the following result

frequency over intensity

Is there anything wrong with my logic here? I've been trying to figure out this problem. As you can see, the marker in figure 1 show that at x = 100.4 y= 0.66 , but in the 2nd figure the x =3 (the frequency corresponding to the 100 wavelength) show the value of 0.65.

Can anyone help me figure this out?

Thanks

submitted by /u/Grey1010
[link] [comments]

[FieldTrip question] How to find the acquisition date and time

$
0
0

Hello,

I'm very new to using fieldtrip. My output data is a .mat with a struct called data which has

hdr 1x1 struct

label 52x1 cell

time 1x1 cell

trial 1x1 cell

fsample 512

sample info [1, xxxxx]

cfg 1x1 struct

I didn't write the inital code for it ( .edf to .mat), but I wanted to know how to get the acquisition date in the format yyyy-mm-ddThh:MM:SS and haven't been able to find it in any of the output files. Is there a function I need to call, or somewhere that I'm not looking ? I looked at the documentation, but I couldn't understand it fully and searched google. I saw that someone in their mail list asked the question but it was never answered. If someone knows where I can get the date and time I would greatly appreciate it.

Any help or suggestions are welcome

Thank you.

submitted by /u/mango_choa
[link] [comments]

Closed-loop control with sliding window: Question on one segment.

$
0
0

So, currently I have developed a closed-loop fuzzy control solution to a problem I am working on within the SIMULINK environment. The closed loop starts with a plant model, which includes external inputs. The output of the plant model is fed to a Kalman-based filter, estimating the states that are fed to the fuzzy controller. The control effort of the fuzzy controller then feeds back into the plant model.

Simple, classic control loop which I have gotten to work just fine.

However, I want to make it a bit more adaptive to the sudden changes within the states. My plan is to essentially take the Kalman-filter output and store them up to 10 or 20 seconds. Then I want to run a 5-second moving average or variance window over those stored states. The resulting average or variance value is then a second input to the fuzzy controller.

So essentially, instead of only feeding the estimated states to the controller , I want to feed the controller the results of the moving window in real time as a second input (MISO system I guess). I am just having a hard time picturing how to do this SIMULINK without using a bunch of cascaded memory blocks.

submitted by /u/walmart_security_
[link] [comments]

I have a problem with writing these functions because of this whole lockdown

$
0
0

Hi, in order to pass the matlab I have to send solutions for these questions and the problem is that due to lockdown I had only 1 meeting because the teacher didnt care about online learning. And now I'm struggling with anything related to matlab, so if anyone could help with these I would really appreciate it. Thank you :)

  1. Write function to calculate the surface area of a cylinder of height H and Radius R.

    1. Write function to check if scalar x is in the range <a,b)
  2. Write program that reads a matrix and calculates the sum of all elements in odd-indexed rows

submitted by /u/Kaesedie
[link] [comments]

MATLAB R2019 b installation in ubuntu 18.04

$
0
0

Hello ,

I want to deploy matlab R2019 b on my clients ubuntu 18.04 machine using newtrok License . Could anybody please help me how to configure network license manager and deploy it to multiple client machines .

As i usually install other applications using ubuntu's repositiory , i am just wondering is there a .deb package available for MATLAB 2019b or 2018b versions. If not , is it advised to create a .deb package or any other way to do perform a single line installation for the client ?

Also , i see the steps to install MATLAB 2019a as following :

https://www.cmu.edu/computing/software/all/matlab/matlabinstall-linux.html

I just want to make sure the installation is as per the ubuntu policy as i dont want any crashes post installation. Please advise !

submitted by /u/shruty20
[link] [comments]

Calling Matlab Classes defined in Class folders from Python

$
0
0

Hello r/MATLAB/

I am trying to call some MATLAB scripts from Python using the matlab engine package, and I'm having some difficulties with classes defined in class folders.

This documentation indicates classes can be passed to Python, and this documentation indicates you can receive object handles as a matlab.object type.

The example indicates this should work with the "containers.Map" type, and looking into the MATLAB install directory (in Ubuntu) this appears to follow the same class folder definition: found in

/usr/local/MATLAB/R2018b/toolbox/matlab/datatypes/+containers/@Map/

A colleague has defined some MATLAB classes using the same class folder method as the @Map folder, I have successfully installed the matlab engine python package, and I have successfully called a MATLAB script that makes use of these objects.

I'd like to be able to create these objects, receiving an object handle in python, and then pass these object handles to other MATLAB functions, however I am getting an 'unsupported data type return from MATLAB', despite the documentation indicating I should get a matlab.object data type.

Has anyone had success with this? I've tried manually adding all class folders to the matlab engine path, with no success. I'm a bit stumped at this point - anyone have any ideas or thoughts on what I could do to narrow down the problem?

submitted by /u/Chris_Hemsworth
[link] [comments]

Help - Solving a large n system of non-linear equations with fsolve

$
0
0

Hello all,
Recently I have been studying the Eaton-Kortum model, and my superior has asked me to solve it in MATLAB. The model has 2n+ n^2 number of non-linear equations that need to be solved, and I have been asked to use fsolve tom complete this task. I am not a total beginner to matlab, but I am unfamiliar with the fsolve command and its interaction with other commands in matlab. So, here are my questions and concerns:

N may change and I am not sure how to think about implementing this in the fsolve framework! N represents the number of countries trading. I need to write this code in such a way that Matlab will solve 2n + n^2 equations regardless of any n. The brute force method would just be defining every equation individually. There are three forms for these equations. n equations take one of these forms, n equations take another seperate form, and finally n^2 equations take the third form. I would like to implement a method in which I don't have to type each equation out individually, because we might have a much larger sample of countries in the data (instead of 4 which would give 24 equations, we might have 103 countries). Could anyone point me in the right direction on how to think about this or what technique I might need to apply? My first thought was a for loop, but the equations are indexed by two numbers and for loops only get one index as far as I am aware.

Thank you in advance. If you think I need to be more clear in asking my question, comment below and I can edit for clarity.

submitted by /u/ekaneg
[link] [comments]

ODE help

$
0
0

Hello everyone, I am trying to recreate this OdexLims program on matlab. However I have never had to solve for constants using experimental data. Constants have always been provided for me (in this case the constants for mu_max and Ks). Could someone help explain how I could go about recreating this problem on Matlab? I also could not find any problem like this in my Matlab book. Please let me know if you need anymore information.

Thank you in advance :)

https://preview.redd.it/12vg3jyjzv751.png?width=592&format=png&auto=webp&s=984057d9c73b495b3f46ff5fc1df0cc5797be21e

submitted by /u/EricVelezJustiniano
[link] [comments]

Adding a variable name to an existing table using "for loop"

$
0
0

Hey guys. So, I have been trying to add some variables into my existing table using a for loop (since I haven't got any depth to the library of MATLAB that much because I am more or, less newbie). A little bit of code might help here I guess

[tableRow, tableColumn] = size(tableVar)

for i = 1:tableRow

 tableVar.Properties.VariableNames(tableColumn+i) = {'anyName'} 

end

The compiling returns an error stating "The VariableNames property must contain one name for each variable in the table". It sounds a bit strange to me. I have performed (tableColumn-i) operation using "for loop" just to extract the variable names & it worked as expected. Also note that I am using the same name to create more variable names just to make a test. Thanks in advance.

submitted by /u/MikesVR07
[link] [comments]

Time delay function block

[Tips] Using Subplots in MATLAB

$
0
0

Greetings r/matlab,

I have just published my second installment of MATLAB Coding Tips. You can find the article here. https://medium.com/@cjdellaporta/subplots-in-matlab-34c339082300

This tutorial walks through the different ways that I use subplot() in MATLAB. I find this topic especially powerful for a lot of the work that I do. Hopefully you will as well.

You can also find the source code from the tutorial in the GitHub repo here: https://github.com/ThinkData-science/CodingTips

As I mentioned before, please let me know if there are specific topics that you are interested in learning about.

Thanks!

submitted by /u/seegedp
[link] [comments]
Viewing all 31096 articles
Browse latest View live