https://se.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-08-03T15:42:52Ztag:se.mathworks.com,2005:Question/5031442020-02-01T12:21:11Z2020-08-03T15:42:52Zwhere i can get cvt tunning tutorials I want to learn simscape from the beginning specially for cvt tunningRupesh Chitkarahttps://se.mathworks.com/matlabcentral/profile/authors/15765681tag:se.mathworks.com,2005:Question/5744892020-08-03T15:13:12Z2020-08-03T15:42:30ZHow I can find the index when both signals are high?
I have two signals. I want to find out indixes on which both signals are high. Both signals have the amplitude (0 & 1). Blue signal is shifted at y=1. Please help me. ThanksTehreem Syedhttps://se.mathworks.com/matlabcentral/profile/authors/19121533tag:se.mathworks.com,2005:Question/2149642015-05-04T11:27:33Z2020-08-03T15:39:34ZSimulink Out of memory. Simulation stopsHallo,
I am simulating a complete hybrid car Simulink model with various components which are built using Simscape, Símulink, Driveline etc. I am loading data into the workspace before starting my simulation which is around 1.2MB. The simulation runs for more than 3 hours and accumalates data work 100MB max which is the data stored in scopes and to workspace blocks. This data is important. However the simulation fails at a certain point coz of the error 'Matlab is out of memory'. What does this error mean? Is the Workspace RAM out of nmemory? I have a RAM memory of 4GB in my Computer.
How do I overcome this problem?
Apurvhttps://se.mathworks.com/matlabcentral/profile/authors/3914700tag:se.mathworks.com,2005:Question/5744712020-08-03T14:36:49Z2020-08-03T15:35:35ZPolyfit with other modelHi,
i am new here,
When i get it right polyfit is for polynomials like this: P(a) = c0 * a^0 + c1 * a^1 + c2 * a^2....
But how to get the coefficients from P(a) = 1 + c1 * a^1 + c^* a^2 .... So that the first value is fixed.
I only find this
https://www.mathworks.com/matlabcentral/answers/399683-polyfit-with-odd-powers-only
Do I just have to subtract from A "1" and from the y too and that's it?
(A and y from the link)
greetings
Adri Annhttps://se.mathworks.com/matlabcentral/profile/authors/19120853tag:se.mathworks.com,2005:Question/5745042020-08-03T15:33:55Z2020-08-03T15:33:55ZLoad timeseries from Python into Simulink Hi,
I have never programmed Simulink before and have done very little MATLAB. So please excuse me if it is really simple question.
I have a simulation where I want to alternate one of the signals in the code. The change is time-dependent and I calculate it in my Python code.
I added a user-defined function so I can do the modification, but can't figure out how to load the values i calculated in Python.
I know that my function is called every 0.0001th of an hour and have converted my Python array to the corresponding values. But how do I synchronize them? I tried converting the array to timeseries but it looks that the granularity is 1 second and this is not what I need.
Please advice,
MosheMoshe Kravchikhttps://se.mathworks.com/matlabcentral/profile/authors/19060158tag:se.mathworks.com,2005:Question/5713782020-07-27T23:02:11Z2020-08-03T15:30:01ZMultiple X axis in different scale, but one y axisHello,
How to Add Multiple X axis in different scale? Please help me? It will look like this:
Alpha Boyhttps://se.mathworks.com/matlabcentral/profile/authors/15381153tag:se.mathworks.com,2005:Question/5745012020-08-03T15:28:30Z2020-08-03T15:28:30ZMatrix compare and unkonw relationships to findI have 2 Matrix, for example
Matrix A ={a1 b1 c1; a2 b2 c2; a3 b3 c3}
Matrix B={x1 y1 z1 m1 n1; x2 y2 z2 m2 n2; x3 y3 z3 m3 n3 }
a1 b1 c1 is the result from FEM-Simulation-1, and x1 y1 z1 m1 n1 is the Geometrie-parameter from Simulation-Objekt-1
a2 b2 c2; x2 y2 z2 m2 n2 and the other number in Matrix means the same thing from Simulation-2 and -3.
there must some relationships zwischen Matrix A and B, linear or unlinear, but i don't yet.
How kann i use Matlab this unkonw relationships to find?
which function should i use?
Thankyou very very much for your time!Zuyu Anhttps://se.mathworks.com/matlabcentral/profile/authors/16532151tag:se.mathworks.com,2005:Question/5744982020-08-03T15:25:26Z2020-08-03T15:25:26ZIs it possible to pass time series vectors into simscape blocks for block characterization?I am building a system with simscape fluid blocks. To characterize the fluid blocks, for example a controlled pressure source block, i built another system in simulink that calculates these parameters, like the pressure differential in my example. The calculated pressure differential is no fixed variable but changes within the simulation of my simulink model. So far i only managed to pass a constant variable into the simscape blocks which would lead to a static simscape model.
Is there a possibility to pass the vector containing delta_p and the time into the simscape block so that the dynamics will be considered for the simulation of the simscape model?
Thank you in advance. Thilo Krausehttps://se.mathworks.com/matlabcentral/profile/authors/15283667tag:se.mathworks.com,2005:Question/5744952020-08-03T15:21:16Z2020-08-03T15:21:16ZI'd like to know how can I model a sprind-damper dynamic system in Matlab Code. My goal is to simulate the dynamic behavior of a motorcycle as it rides over a bump. I'd use any help. I'd like to know how can I model a sprind-damper dynamic system in Matlab Code. My goal is to simulate the dynamic behavior of a motorcycle as it rides over a bump. I'd like to model it in Matlab code, I've already done it in simulink. Any advisewill help. joan oliverhttps://se.mathworks.com/matlabcentral/profile/authors/12468406tag:se.mathworks.com,2005:Question/5734902020-07-31T16:46:56Z2020-08-03T15:20:08ZWhy is corr/corrcoef returning NaNs?I have 2 vectors that I would like to correlate with one another: OptimismBias and AmbigTolG (listing the first 10 values out of 248).
-0.0263 0.0000
0.7971 0.0000
-0.2800 -0.0000
0.4088 0.0000
0.6691 0.0000
0.5348 NaN
0.2606 0.0000
0.6995 NaN
-0.3270 0.0000
0.4665 0.0139
When I run the corr, I get all NaNs at the output. I'm aware that the AmbigTolG values are 0 or close to 0 but I'm not sure how else to run this.Darla Bonagurahttps://se.mathworks.com/matlabcentral/profile/authors/14744304tag:se.mathworks.com,2005:Question/5743182020-08-03T08:20:26Z2020-08-03T15:16:03ZSection an array into equal rows and changing simultaneously the values of each section.I've been trying to section a matrix into equal rows while changing simultaneously the values of each section but I've been stuck for a while now please I need help. Thanks.Princewill Azoromhttps://se.mathworks.com/matlabcentral/profile/authors/19119386tag:se.mathworks.com,2005:Question/5744832020-08-03T14:52:13Z2020-08-03T15:14:03ZGreek character in script turned to a square or a question mark - any ideas why?I copied a script from an older computer with Matlab 2012b to a new computer with Matlab 2017a and when I opened it, a Greek character 'μ' was encoded as a little square (maybe missing font). After Installing the Greek language option in MS Windows and typing in its place the letter μ, running the script reported an error (wrong matrix dimensions). So I reloaded the saved script and the character μ had now been replaced by a questionmark. Does anyone know what is going on? I have not witnessed this before. The faulty character encoding may have nothing to do with Matlab itself.Nick Aggelopouloshttps://se.mathworks.com/matlabcentral/profile/authors/18946353tag:se.mathworks.com,2005:Question/4694572019-06-29T07:43:29Z2020-08-03T15:11:56ZWrite a function called valid_date that takes three positive integer scalar inputs year, month, day. If these three represent a valid date, return a logical true, otherwise false. The name of the output argument is valid. If any of the inputs is not unction valid=valid_date(year,month,date)
if nargin==3
valid1=true;
else valid=false;
return
end
v1=[year]; v2=[month]; v3=[date];
if isscalar(v1)==true && isscalar(v2)==true && isscalar(v3)==true
valid2=true;
else valid=false;
return
end
if year>0 && 0<month && month<=12 && 0<date && date<=31
valid3=true;
else valid=false;
return
end
a=year/4; b=year/100; c=year/400;
if rem(year,4)==0 && rem(year,100)~=0
valid4=true;
else valid4=false;
end
if rem(year,100)==0 && rem(year,400)~=0
valid5=true;
else valid5=false;
end
if rem(year,400)==0
valid4=true;
else valid4=false;
end
if (month==1||3||5||7||8||10||12 && date<=31) || (month==2 && date<=29) || (month==4||6||9||11 && date<=30) && valid4==true && valid5==false
valid6=true;
else valid6=false;
end
if (month==1||3||5||7||8||10||12 && date<=31) || (month==2 && date<=28) || (month==4||6||9||11 && date<=30) && valid5==true && valid4==false
valid7=true;
else valid7=false;
end
if valid1==true && valid2==true && valid3==true && valid6==true
valid=true;
elseif valid1==true &&valid2==true && valid3==true && valid7==true
valid=true;
else
valid=false;
return
end
why this code is not working for 2018/4/31 and 2003/2/29? and other random dates. but is works for non scalar and random leap yearsAjith Thomashttps://se.mathworks.com/matlabcentral/profile/authors/14974985tag:se.mathworks.com,2005:Question/5744802020-08-03T14:50:09Z2020-08-03T15:11:27ZCount the number of indices between two indicesI have an array B with 1s, -1s and 0s. Such as:
[ 0 0 0 0 0 1 0 0 0 -1 0 0 0 1 -1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 -1 0 ]
I would like to count the number of indices there between each 1 and -1
result should be: 3 0 8
num = B(index_of_1 : index_of_-1);
Since the index changes constanly, I am stuck on how to write the B( : ) part. Anybody have an idea? Djdj Cjcjxjhttps://se.mathworks.com/matlabcentral/profile/authors/19121436tag:se.mathworks.com,2005:Question/5727312020-07-30T08:52:36Z2020-08-03T15:07:20ZWrap Xilinx IP in Simulink black boxHi all,
I have done several of the Xilinx tutorials for black-box wrapping of HDL in Simulink but have not come across one yet where more than one HDL file is used. I have a fairly large HDL codebase with ~40 files.
My top file makes use of all the other files (which are contained within pre-defined libraries). I am doubtful as to whether wrapping my top file in a black-box (which I have done) in Simulink, will work. I understand that I could just include all my hdl files in the config.m script, but how would I infer the libraries each set of files belong to?
I have a working Vivado project for this build but asides from that, I am unsure how I need to tell Simulink (and by association system generator) about the hierarchy/libraries/multiple files for correct synthesis and implementation. Do I need to supply accompanying tcl scripts? Is there a way to pass the Vivado project file to System Generator in Simulink? Could I create a custom IP from the Vivado project for wrap that in a black box?
Please assist.
I am happy to share my .slx and config.m (for the black box I have created for my top vhdl file), and Vivado project should you need it.
Thank you.
Using: Vivado 2019.1 and Matlab 2019a.
Talon Myburgh.
Below you can see a screenshot of my black box I've created in Simulink:
Simulink black box of my top HDL file. Block shows in/out ports available and window beside it shows customisable generics. A system generator block is present in the design so that Simulink knows to hand off the design to System Generator in Vivado for Synthesis and Implementation. Talon Myburghhttps://se.mathworks.com/matlabcentral/profile/authors/8194740tag:se.mathworks.com,2005:Question/5741982020-08-02T23:11:29Z2020-08-03T15:06:25ZNeed to create a script that calculates the average of a set of numbers.I need to creat a script that calculates the average of a set of positive numbers.
However there are 2 peculiarities about this script. Firstly, the user has to input his numbers one at a time. And secondly, the user is meant to end the cycle of inputing numbers by inputting a negative number. Such that if the user writes in 3, 4, 5, 6 and -3. The set will be [3, 4, 5, 6]. Also, I am to use a While loop.
This is what I have so far
clearvars
n=2;
Y= input('Enter your set of numbers');
while Y>=0
Y(n) = input('Enter your set of numbers');
n=n+1;
end
Mean=mean(Y)
Firstly, it's quite incosistent for some reason. I get this error message every now and then.
Error using internal.matlab.desktop_workspacebrowser.MLWorkspaceDataModel/workspaceUpdated (line 109)
Reference to non-existent field 'Mean'.
Error in internal.matlab.datatoolsservices.WorkspaceListener>@(es,ed)evalin('caller',cmd) (line 162)
foo = @(es,ed)evalin('caller', cmd);
Error using internal.matlab.desktop_workspacebrowser.MLWorkspaceDataModel/workspaceUpdated (line 109)
Reference to non-existent field 'Mean'.
Error in internal.matlab.datatoolsservices.WorkspaceListener>@(es,ed)evalin('caller',cmd) (line 162)
foo = @(es,ed)evalin('caller', cmd);
typing clearvars seems to solve this, even though I have it on the script too.
And also, although inputting a negative number does end the script. It is inevitably taken into account when I calculate the average, which I don't want.
Any tips on how to improve on this?Gabe Strongbackhttps://se.mathworks.com/matlabcentral/profile/authors/19117059tag:se.mathworks.com,2005:Question/5682422020-07-21T09:29:30Z2020-08-03T15:01:09ZCan Voltage dependent capacitance be modeled in Simscape?Can a voltage dependent capacitance be represented directly using capacitor or any other in built block in Simscape model? Or it has to be modelled in terms of equations using Simulink ?Amruta Joshihttps://se.mathworks.com/matlabcentral/profile/authors/17133263tag:se.mathworks.com,2005:Question/4494212019-03-11T13:50:40Z2020-08-03T14:59:16ZCreate a sphere using surface equationThe surface equation of a sphere is (x-a)^2+(y-b)^2+(z-c)^2-r^2=0.
What I pretend is to create a sphere surface using the equation above. And then get an output matrix with the x,y,z values of the sphere surface nodes...
I don't want to use the sphere function because I intend to create multiple spheres and get the x,y,z values to each one of them. With sphere function I dont know if it would be possible.
Can somebody help me please?Cristiana Abilheirahttps://se.mathworks.com/matlabcentral/profile/authors/11186212tag:se.mathworks.com,2005:Question/5690222020-07-22T14:09:20Z2020-08-03T14:58:50ZHow can I remove the lines that are not in the cross section of the annulus?Cnellhttps://se.mathworks.com/matlabcentral/profile/authors/14677359tag:se.mathworks.com,2005:Question/5744742020-08-03T14:39:13Z2020-08-03T14:56:26ZMaking a GUI to zoom in on x-axis rangeI am looking to make a GUI where the user for this program can specify a range such as June to August and it will zoom in on that range? Is this possible? Any examples are appreaciated
Austin Matuszewskihttps://se.mathworks.com/matlabcentral/profile/authors/17016166tag:se.mathworks.com,2005:Question/5744862020-07-17T04:00:00Z2020-08-03T14:55:55ZWhy does long-press to insert an accented character on Mac prevent further input in the MATLAB Editor and Command Window?Why does long-press to insert an accented character on Mac prevent further input in the MATLAB Editor and Command Window?
MathWorks Support Teamhttps://se.mathworks.com/matlabcentral/profile/authors/4622813tag:se.mathworks.com,2005:Question/5744472020-08-03T13:22:42Z2020-08-03T14:53:31ZHow to Use arrayfun with a Multivariate Function of n Variables?Suppose f(X) is a function of a vector X = [x1, x2, ..., xn]. How to evaluate the function at a certain range of values, say y1, y2, ..., ym, for the variable xi while keeping all other variables fixed?
To make it simple: Say x1, ..., x59, x61, ..., x100 = 10, and we want to evaluate the function for three different values for x60, say at 1.5, -3, and 12. Can we do this without for loops?Kareem Elgindyhttps://se.mathworks.com/matlabcentral/profile/authors/14880382tag:se.mathworks.com,2005:Question/5689802020-07-22T12:49:41Z2020-08-03T14:47:55ZSimscape model, black box or white box?The Simscape is a library with physical components to create a physical model. A model built with Simscape would be a white box (a model that we know exactly how it works) or a black box (a model that was created and we don't have acess to its functioning completely)? Or somehow a grey box?Matheus Andradehttps://se.mathworks.com/matlabcentral/profile/authors/18951465tag:se.mathworks.com,2005:Question/467362012-08-26T08:09:46Z2020-08-03T14:43:35ZHow to resolve the "Index exceeds matrix dimensions" error ? if true
data = getdata(vid,50,'double','cell');
for i=1:5:100
data{i}(:,:,1)=(data{i}(:,:,1))+(data{i+1}(:,:,1))+(data{i+2}(:,:,1))+ ...
(data{i+3}(:,:,1))+(data{i+4}(:,:,1))/5;
data{i}(:,:,3)=(data{i}(:,:,3))+(data{i+1}(:,:,3))+(data{i+2}(:,:,3))+...
(data{i+3}(:,:,3))+(data{i+4}(:,:,3))/5;
data{i}(:,:,2)=(data{i}(:,:,2))+(data{i+1}(:,:,2))+(data{i+2}(:,:,2))+...
(data{i+3}(:,:,2))+(data{i+4}(:,:,2))/5;
end
end
[EDITED, Jan, code formatted - Please do this by your own, thanks!]sadhnahttps://se.mathworks.com/matlabcentral/profile/authors/3624111tag:se.mathworks.com,2005:Question/5744772020-08-03T14:42:46Z2020-08-03T14:42:46ZCode not running and showing busyDear programmers
I have written a piece of code. Please check after providing convergence criteria with while loop the code is not running and only showing as busy. Please help.
Regards
Rajdeep
input= xlsread('Input');
output = xlsread('Output');
bias = ones(1,3)*0.0005; %bias values
a=-1;
b=1;
rng('default')
V= a+(b-a)*rand(6,5); %weights between the input(6 nodes) and hidden(5 nodes) layers
rng('default')
W = a+(b-a)*rand(5,1); %weights between the hidden(5 nodes) and output(1 node) layers
transposed_input = input'; %inputs
d = output'; %target output
%initialization of del[W] and del[V]
del_W1=0;
del_W2=0;
del_W3=0;
del_W4=0;
del_W5=0;
del_V1=0;
del_V2=0;
del_V3=0;
del_V4=0;
del_V5=0;
del_V6=0;
del_V7=0;
del_V8=0;
del_V9=0;
del_V10=0;
del_V11=0;
del_V12=0;
del_V13=0;
del_V14=0;
del_V15=0;
del_V16=0;
del_V17=0;
del_V18=0;
del_V19=0;
del_V20=0;
del_V21=0;
del_V22=0;
del_V23=0;
del_V24=0;
del_V25=0;
del_V26=0;
del_V27=0;
del_V28=0;
del_V29=0;
del_V30=0;
for epoch=1:6000 %number of iterations
alpha=0.1; %learning rate
Mu=0.1; %Momentum Constant
N=80; %Number of training cases
for k=1:N
%Feed-Forward Network starts
%Output to input neurons
OI(1,k)=1./(1+exp(-(transposed_input(1,k)+bias(1,1))));
OI(2,k)=1./(1+exp(-(transposed_input(2,k)+bias(1,1))));
OI(3,k)=1./(1+exp(-(transposed_input(3,k)+bias(1,1))));
OI(4,k)=1./(1+exp(-(transposed_input(4,k)+bias(1,1))));
OI(5,k)=1./(1+exp(-(transposed_input(5,k)+bias(1,1))));
OI(6,k)=1./(1+exp(-(transposed_input(6,k)+bias(1,1))));
%Input to hidden neurons
IH1(1,k)= (OI(1,k)*V(1,1))+(OI(2,k)*V(2,1))+ (OI(3,k)*V(3,1))+ (OI(4,k)*V(4,1))+ (OI(5,k)*V(5,1))+(OI(6,k)*V(6,1))+bias(1,2);
IH2(1,k)= (OI(1,k)*V(1,2))+(OI(2,k)*V(2,2))+ (OI(3,k)*V(3,2))+ (OI(4,k)*V(4,2))+ (OI(5,k)*V(5,2))+(OI(6,k)*V(6,2))+bias(1,2);
IH3(1,k)= (OI(1,k)*V(1,3))+(OI(2,k)*V(2,3))+ (OI(3,k)*V(3,3))+ (OI(4,k)*V(4,3))+ (OI(5,k)*V(5,3))+(OI(6,k)*V(6,3))+bias(1,2);
IH4(1,k)= (OI(1,k)*V(1,4))+(OI(2,k)*V(2,4))+ (OI(3,k)*V(3,4))+ (OI(4,k)*V(4,4))+ (OI(5,k)*V(5,4))+(OI(6,k)*V(6,4))+bias(1,2);
IH5(1,k)= (OI(1,k)*V(1,5))+(OI(2,k)*V(2,5))+ (OI(3,k)*V(3,5))+ (OI(4,k)*V(4,5))+ (OI(5,k)*V(5,5))+(OI(6,k)*V(6,5))+bias(1,2);
%Output to hidden neurons
OH1(1,k) = (exp(IH1(1,k)+bias(1,2)) - exp(-(IH1(1,k)+bias(1,2))))./(exp(IH1(1,k)+bias(1,2)) + exp(-(IH1(1,k)+bias(1,2))));
OH2(1,k) = (exp(IH2(1,k)+bias(1,2)) - exp(-(IH2(1,k)+bias(1,2))))./(exp(IH2(1,k)+bias(1,2)) + exp(-(IH2(1,k)+bias(1,2))));
OH3(1,k) = (exp(IH3(1,k)+bias(1,2)) - exp(-(IH3(1,k)+bias(1,2))))./(exp(IH3(1,k)+bias(1,2)) + exp(-(IH3(1,k)+bias(1,2))));
OH4(1,k) = (exp(IH4(1,k)+bias(1,2)) - exp(-(IH4(1,k)+bias(1,2))))./(exp(IH4(1,k)+bias(1,2)) + exp(-(IH4(1,k)+bias(1,2))));
OH5(1,k) = (exp(IH5(1,k)+bias(1,2)) - exp(-(IH5(1,k)+bias(1,2))))./(exp(IH5(1,k)+bias(1,2)) + exp(-(IH5(1,k)+bias(1,2))));
%Input to Output neuron
IO(1,k)=OH1(1,k)*W(1,1)+OH2(1,k)*W(2,1)+OH3(1,k)*W(3,1)+OH4(1,k)*W(4,1)+OH5(1,k)*W(5,1)+bias(1,3);
%Output to Output neuron
Out(1,k)=IO(1,k)+bias(1,3);
%forward step calculation corresponding to each training case of a batch run terminates here
%BackPropagation of [V] and [W] starts
%Finding Mean Squared Error(E)
error(1,k)=d(1,k)-Out(1,k);
diff_Out(1,k)=[error(1,k).^2];
E= sum(diff_Out(1,k))./(2*N);
end
while (E >= 0.0004) %convergence criteria
for p=1:N
delta(1,p)=Out(1,p)*(1-Out(1,p))*error(1,p);
del=sum(delta(1,p));
%summation of Output to hidden neurons for 'k' training cases
OHS1=sum(OH1(1,p));
OHS2=sum(OH2(1,p));
OHS3=sum(OH3(1,p));
OHS4=sum(OH4(1,p));
OHS5=sum(OH5(1,p));
%summation of Output to input neurons for 'k' training cases
OI1=sum(OI(1,p));
OI2=sum(OI(2,p));
OI3=sum(OI(3,p));
OI4=sum(OI(4,p));
OI5=sum(OI(5,p));
OI6=sum(OI(6,p));
end
delta2_1=OHS1*(1-OHS1)*W(1,1)*del;
delta2_2=OHS2*(1-OHS2)*W(2,1)*del;
delta2_3=OHS3*(1-OHS3)*W(3,1)*del;
delta2_4=OHS4*(1-OHS4)*W(4,1)*del;
delta2_5=OHS5*(1-OHS5)*W(5,1)*del;
%delta[W]
del_W1=-alpha*OHS1*del+Mu*del_W1;
del_W2=-alpha*OHS2*del+Mu*del_W2;
del_W3=-alpha*OHS3*del+Mu*del_W3;
del_W4=-alpha*OHS4*del+Mu*del_W4;
del_W5=-alpha*OHS5*del+Mu*del_W5;
%delta[V]
del_V1=-alpha*OI1*delta2_1+Mu*del_V1;
del_V2=-alpha*OI2*delta2_1+Mu*del_V2;
del_V3=-alpha*OI3*delta2_1+Mu*del_V3;
del_V4=-alpha*OI4*delta2_1+Mu*del_V4;
del_V5=-alpha*OI5*delta2_1+Mu*del_V5;
del_V6=-alpha*OI6*delta2_1+Mu*del_V6;
del_V7=-alpha*OI1*delta2_2+Mu*del_V7;
del_V8=-alpha*OI2*delta2_2+Mu*del_V8;
del_V9=-alpha*OI3*delta2_2+Mu*del_V9;
del_V10=-alpha*OI4*delta2_2+Mu*del_V10;
del_V11=-alpha*OI5*delta2_2+Mu*del_V11;
del_V12=-alpha*OI6*delta2_2+Mu*del_V12;
del_V13=-alpha*OI1*delta2_3+Mu*del_V13;
del_V14=-alpha*OI2*delta2_3+Mu*del_V14;
del_V15=-alpha*OI3*delta2_3+Mu*del_V15;
del_V16=-alpha*OI4*delta2_3+Mu*del_V16;
del_V17=-alpha*OI5*delta2_3+Mu*del_V17;
del_V18=-alpha*OI6*delta2_3+Mu*del_V18;
del_V19=-alpha*OI1*delta2_4+Mu*del_V19;
del_V20=-alpha*OI2*delta2_4+Mu*del_V20;
del_V21=-alpha*OI3*delta2_4+Mu*del_V21;
del_V22=-alpha*OI4*delta2_4+Mu*del_V22;
del_V23=-alpha*OI5*delta2_4+Mu*del_V23;
del_V24=-alpha*OI6*delta2_4+Mu*del_V24;
del_V25=-alpha*OI1*delta2_5+Mu*del_V25;
del_V26=-alpha*OI2*delta2_5+Mu*del_V26;
del_V27=-alpha*OI3*delta2_5+Mu*del_V27;
del_V28=-alpha*OI4*delta2_5+Mu*del_V28;
del_V29=-alpha*OI5*delta2_5+Mu*del_V29;
del_V30=-alpha*OI6*delta2_5+Mu*del_V30;
end
%updated [W] and [V] matrix
W(1,1)=W(1,1)+del_W1;
W(2,1)=W(2,1)+del_W2;
W(3,1)=W(3,1)+del_W3;
W(4,1)=W(4,1)+del_W4;
W(5,1)=W(5,1)+del_W5;
V(1,1)= V(1,1)+del_V1;
V(2,1)= V(2,1)+del_V2;
V(3,1)= V(3,1)+del_V3;
V(4,1)= V(4,1)+del_V4;
V(5,1)= V(5,1)+del_V5;
V(6,1)= V(6,1)+del_V6;
V(1,2)= V(1,2)+del_V7;
V(2,2)= V(2,2)+del_V8;
V(3,2)= V(3,2)+del_V9;
V(4,2)= V(4,2)+del_V10;
V(5,2)= V(5,2)+del_V11;
V(6,2)= V(6,2)+del_V12;
V(1,3)= V(1,3)+del_V13;
V(2,3)= V(2,3)+del_V14;
V(3,3)= V(3,3)+del_V15;
V(4,3)= V(4,3)+del_V16;
V(5,3)= V(5,3)+del_V17;
V(6,3)= V(6,3)+del_V18;
V(1,4)= V(1,4)+del_V19;
V(2,4)= V(2,4)+del_V20;
V(3,4)= V(3,4)+del_V21;
V(4,4)= V(4,4)+del_V22;
V(5,4)= V(5,4)+del_V23;
V(6,4)= V(6,4)+del_V24;
V(1,5)= V(1,5)+del_V25;
V(2,5)= V(2,5)+del_V26;
V(3,5)= V(3,5)+del_V27;
V(4,5)= V(4,5)+del_V28;
V(5,5)= V(5,5)+del_V29;
V(6,5)= V(6,5)+del_V30;
endRajdeep Ghoshhttps://se.mathworks.com/matlabcentral/profile/authors/16028585tag:se.mathworks.com,2005:Question/5741172020-08-02T16:13:32Z2020-08-03T14:39:43ZDivided interest of space (ROI) into continuous cubesHello
Dear Friends
I have a Lider result consist of X, Y, Z in matlab file and for each cell/frame I want to divide the region of interest (ROI) space (X: -150m to 150m; Y:-100m to 100m; Z: -15m to 15m) into continuous cubes (0.1m cube length) and calculate the point density in each cube.
clc
close all
fileDir = 'D:\Examps'; % the target data directory
%outfile = 'D:\XYZ_14000.csv';
fid=fopen(outfile,'w');
d=dir(fullfile(fileDir,'*.csv')); % dir() struct of *.csv files in directory
N=numel(d); % total number files found
for i = 1:N % iterate over them...
XYZ=readmatrix(fullfile(fileDir,d(i).name),'NumHeaderLines',1);
data=XYZ(:,1:3); % select the three columns only
fmt=[repmat('%f,',1,numel(data)-1) '%f\n'];
fprintf(fid,fmt,data);
X=XYZ(1:4,1);
Y=XYZ(1:4,2);
Z=XYZ(1:4,3);
% if -100<=X<=100
% X=Xlimit
%else X'='0
end
fid=fclose(fid);
ThanksEhsan Shooshtarihttps://se.mathworks.com/matlabcentral/profile/authors/16790198tag:se.mathworks.com,2005:Question/5744262020-08-03T12:49:24Z2020-08-03T14:36:23ZDecision tree/regression tree, how does the algorithm chose a value for the root node?Decision tree/regression tree, how does the algorithm chose a value for the root node? I'm getting a seemingly random value that starts the split. It isn't the median in the dataset. How is Matlab choosing the beginning value?
For example in the data, my Max value is 25, my min value is 3, the median is 8, but the tree is choosing a root node split of 11.5 when that value isn't even in the dataset. How is this number chosen?Christiana Sasserhttps://se.mathworks.com/matlabcentral/profile/authors/10384800tag:se.mathworks.com,2005:Question/5172582020-04-12T06:07:35Z2020-08-03T14:34:25ZGeneration Rate Constraint, modelling it in Simulink
I'm doing a research project on Generation Rate Constraint and from most research papers I've read, GRC is modelled by a limiter in Simulink. There is a rate limiter in Simulink but I noticed that the symbol used there is much different than the ones used in the research papers. I was wondering whether despite having a different symbol, do they both work in the same way?
p.s. the research papers I read uses Simulink as well
; this is the symbol for limiter used in Simulink
; this is the symbol for limiter in the research papers
Essif Yahyahttps://se.mathworks.com/matlabcentral/profile/authors/16629659tag:se.mathworks.com,2005:Question/5716512020-07-28T13:18:21Z2020-08-03T14:33:52Zhow can I increase the patch animation speed?I am developing a simulation that animates a 3D model. For the visualisation I work with patches. But the speed drops as the number of vertices increase. I have written the below example. In the profiler I see that most time is spent on the command: drawnow. Is there a way to speed this up?
%% Draw a cylindrical patch object
n = 20000;
alpha = linspace(0,360,n);
vertices = zeros(3,2*n);
vertices([1 2],1:n) = [cosd(alpha); sind(alpha)] * 1;
vertices([1 2],n+1:2*n) = vertices([1 2],1:n);
vertices(3,n+1:2*n) = 1;
faces = [1:n; [2:n 1]; [n+2:2*n n+1]; n+1:2*n]';
hp = patch( ...
'EdgeColor', 'none', ...
'FaceColor', [0 0 1], ...
'Faces', faces, ...
'Vertices', vertices');
%% Make up axis
axis equal
axis([-2 2 -2 2 -2 2])
view(20,30)
%% Animate and calculate fps
m = 90;
range = linspace(0,90,m);
Rxx = eye(3);
profile on
tic
for phi = range
Rxx = [1 0 0; 0 cosd(phi) -sind(phi); 0 sind(phi) cosd(phi)];
hp.Vertices = (Rxx * vertices)';
drawnow
end % for phi = range
fps = m/toc
profile viewerPeter Jan Steinbuschhttps://se.mathworks.com/matlabcentral/profile/authors/759627tag:se.mathworks.com,2005:Question/3366242017-04-22T02:38:01Z2020-08-03T14:33:24ZHow to use a trained neural network in matlab??I am not using neural net toolbox rather I am using my own code to build a neural net model.
Now after saving my neural net result, I want to test it with new data set. How to do this???saif ikbalhttps://se.mathworks.com/matlabcentral/profile/authors/8594711tag:se.mathworks.com,2005:Question/5744652020-08-03T14:15:58Z2020-08-03T14:32:46ZHow can one generate a matrix that the first column is larger than the second column?In a previous question I have learned that, given a matrix, how to pick the rows that the first column entry is larger than the second column entry.
V=V(V(:,1)>=V(:,2),:)
Then, now, I want to generate a 1000*2 matrix where each entry is from randn and that the first column is larger than the second column. alpedhuezhttps://se.mathworks.com/matlabcentral/profile/authors/10930090tag:se.mathworks.com,2005:Question/5741682020-08-02T19:50:28Z2020-08-03T14:28:03ZHow can one extract this vector from a matrix?First, suppose I have a matrix M of 60 rows and 3 columns. Suppose each row is a month like January, February, ... so that every 12 months make a year.
Second, I now want to create a matrix Y of 5 rows and 2 columns where each row represents year and the second column is the yearly average of entries of the second column and the third columns of each year.
How can one write a program?
(Just to make sure, the actual case is not about months and year so it is not that one wants to use retime and other time related function.)alpedhuezhttps://se.mathworks.com/matlabcentral/profile/authors/10930090tag:se.mathworks.com,2005:Question/5744682020-08-03T14:27:19Z2020-08-03T14:27:19ZWithin-Subject EffectHello everyone,
Please check the table attached. I am trying to do a repeated measures anova where the tertiles (t1,t2,t3) are the within-subject factor and the group (scroll down the table to see the 2 groups) is the between-subject factor.
This is what I've done and with the rm.ranova I manage to get the effect of group:tertile (p=0.30501) and with the anova() I manage to get the effect of group (p= 0.15493). However, I want to know the p-value of the effect of the within-subject factor. I used another software and I know it will be 0.595, but how can I get this value with matlab?Thank you.
new_data.Properties.VariableNames(3:5) = {'t1', 't2', 't3'};
% The within-subjects design
withinDsgn = table((1:3)','VariableNames',{'Tertile'});
% Run the RM Anova
rm = fitrm(new_data, 't1-t3~Group', 'WithinDesign', withinDsgn);
rm.ranova
aresults = anova(rm);
aresultsHappy Bearhttps://se.mathworks.com/matlabcentral/profile/authors/17410125tag:se.mathworks.com,2005:Question/5631082020-07-10T22:43:44Z2020-08-03T14:25:49ZLSTM cell operation with different number of hidden unitsIn this link, workings of LSTM in MATLAB is explained to some degree, however I need some clarification:
Let, I have 400 time steps where each will include 100-long feature vectors.
a) Assume I set LSTM hidden unit number to 1. From my intuition, from time 0 to 399, this unit will receive all feature vectors in order and process them sequentially till the end, 400th vector at step 399.
b) Now assume hidden unit number is 50. Then what I understant from documentation is, the 50 stacked units will receive first feature vector at time step 0, and of course they will receive inputs from each other depending on the hidden unit topology. At time step 1, second feature vector will propagate through the topology with other inputs and so on.
Did I interpret it right or miss something else?
Another question, when I set LSTM hidden layer number to 50, how do I know the topology?Neon Argentushttps://se.mathworks.com/matlabcentral/profile/authors/14569364tag:se.mathworks.com,2005:Question/5706252020-07-26T02:17:47Z2020-08-03T14:24:06ZHelp integrating particle intensityI'm trying to integrate the intensity from each of the particles in the following image to determine if there are any outliers that need to be discarded:
From what I understand, this is done by summing all the pixels in the PSF by summing the value of the all the pixels contained within a box surrounding each particle defined my the size of the maximum FWHM value.
So right now I have x and y locations for each particle and sigma values for the PSF. Here's the code I have now:
numParticles = numel(sigma);
fwhm = 2.355*sigma;
fwhm = max(fwhm);
fwhm = round(fwhm);
x0 = round(position(:,1)); y0 = round(position(:,2));
for ii=1:numParticles
x = x0(ii)+(-fwhm:fwhm); y = y0(ii)+(-fwhm:fwhm);
x = x(x>0); y = y(y>0);
intensity(ii) = sum(sum(im(x,y),2),1);
end
The problem I'm having is that I'm getting a lot of negative values, which doesn't make sense to me. Can someone point out if I'm doing something wrong?Jhttps://se.mathworks.com/matlabcentral/profile/authors/17263087tag:se.mathworks.com,2005:Question/5744622020-08-03T14:12:30Z2020-08-03T14:12:30ZSin and delta functions in matrix Hello , how can i creat two matirces one of them is sin function with 3*3 matrix and the second one is delta function with 3*3 matrix ,appreciate your support.Firas Kareemhttps://se.mathworks.com/matlabcentral/profile/authors/18950876tag:se.mathworks.com,2005:Question/5744592020-08-03T14:00:00Z2020-08-03T14:09:23ZHow can I solve this ?! Y=square(120t)+cos(980t)-1.5
Design IIR filter to remove DC component from the signal tasneem haririhttps://se.mathworks.com/matlabcentral/profile/authors/11857258tag:se.mathworks.com,2005:Question/5684702020-07-21T16:08:52Z2020-08-03T14:04:27ZConfusion Matrix class-label I want to write the class labels of my confusion matrix as 'f subscript 1', 'f subscript 2' etc. However when I am defining as
cm = confusionchart([20 0 0; 0 20 0; 0 0 20],{'f_1','f_2','f_3'}),,,But the class labels are coming as 'f_1', 'f_2' etc. The subscripts are not coming.
I have also tried this...cm = confusionchart([20 0 0; 0 20 0; 0 0 20],{'$f_1$','$f_2$','$f_3$'}, 'Interpreter','latex' )....This is showing an error message.
Can anybody please help me out?Ayush Chatterjeehttps://se.mathworks.com/matlabcentral/profile/authors/18187359tag:se.mathworks.com,2005:Question/5742342020-08-03T03:35:02Z2020-08-03T13:59:13Zanimate 2d plotHi, All!
Say i have 2 variable, x1 and x2. I wanna plot (x1, x2) and animate it over time. i've tried this code:
x = [1 2;2 1;3 1;1 2;2 1;3 2];
x1 = x(1:end,1);
x2 = x(1:end,2);
r=animatedline;
for t=1:1000
for i=1:6
x1(i,t+1)=x1(i,t)+3;
x2(i,t+1)=x2(i,t)+x1(i,t);
end
addpoints(r,x1(1,:),x2(1,:))
addpoints(r,x1(2,:),x2(2,:))
drawnow
end
But that's not what i meant. From code above, the first line move from (1,2) to (4,3) to (7,7).... the second line move from (2,1) to (5,3), to (8,8),...
till the figure show the movement of those 6 lines.Nur Amalinahttps://se.mathworks.com/matlabcentral/profile/authors/7681873tag:se.mathworks.com,2005:Question/5744562020-08-03T13:58:24Z2020-08-03T13:58:24Z ploting vector function that each of it's component has more than one variable. how can i introduce the direction of each component that has two variable in Matlab i have written a program but i guess it is maybe wrong. i will be so thankful for how can write program for vector function which has 3 components that each of them has 2 variable?
like this;
E= sin(x) exp(-y) (in direction of x)+cos(x) exp(-y)(in direction of y) .
I have written this program but i doubt it is true
x=0:1:400;
y=0:2:800;
[x,y]=meshgrid(x,y);
u=0.67.*sin(0.019.*x-32.59).*exp(-y./90.2);
v=1.62.*cos(0.019.*x-32.59).*exp(-y./90.2);
i=x./norm(x);
j=y./norm(y);
e=u.*i+v.*j;
plot3(x,y,e);sarina yhttps://se.mathworks.com/matlabcentral/profile/authors/19120887tag:se.mathworks.com,2005:Question/5744232020-08-03T12:32:45Z2020-08-03T13:54:08ZHow do I partition a n by m matrix into equal rows How do I partition an n by m matrix into equal rows please I've been trying to write a script that does this but I haven't been having much progress please can anyone help mePrincewill Azoromhttps://se.mathworks.com/matlabcentral/profile/authors/19119386tag:se.mathworks.com,2005:Question/5736942020-08-01T09:48:22Z2020-08-03T13:53:31ZNull coefficients when classifying an imageHello guys! I have a question related to image classification problems.
After training my network and finishing the offline phase and saved trained network.
Trained network : mynet= trainNetwork(augmentedTrainingSet, lgraph, opts);
I want to count the number of null coefficients of the network (unused weights) when classifying the image in the online phase to make a comparision and determine the reason of time gain between many networks.
%% Make a prediction using the classifier
[YPred,probs] = classify (mynet, newimage);
So after making this prediction in the online phase, how can I get the connections' weights used in the classification of this new image?
Thank you! Appreciate any help!Andrea Daouhttps://se.mathworks.com/matlabcentral/profile/authors/14442462tag:se.mathworks.com,2005:Question/5744292020-08-03T04:00:00Z2020-08-03T13:53:13ZWhy does MATLAB R2020a not rendering correctly when Japanese locale is selected on Redhat 8.x?When running the MATLAB just after the fresh installation on Redhat 8.x, the labels/names for the toolstrip aren't rendered when the locale is set to Japanese.MathWorks Support Teamhttps://se.mathworks.com/matlabcentral/profile/authors/4622813tag:se.mathworks.com,2005:Question/5744022020-08-03T11:41:31Z2020-08-03T13:52:36Zcreate multiple submatrices from a large matrixDear All communtity members,
I want to write a code that creates multiple submatrices from a large matrix either through a loop or by vectorization.
The large matrix has a dimension of 54x7056 and I want to create 16 submatrices selected from different columns.
The submatrices shall be selected and repeated as following;
sub1= column, 1, 9 to 17, 25 to 33, 41 to 49.......................... and 7049 to 7056.
sub2= column, 1 to 2, 10 to 18,26 to 34, 42 to 50.................. and 7050 to 7056.
sub3= column, 1 to 3, 11 to 19,27 to 35, 43 to 51.................. and 7051 to 7056.
sub4= column, 1 to 4, 12 to 20, 28 to 36, 44 to 52................. and 7052 to 7056.
sub5= column, 1 to 5, 13 to 21, 29 to 37, 45 to 53.....7037 to 7045, and 7053 to 7056.
sub6= column, 1 to 6, 14 to 22, 30 to 38, 46 to 54.... 7038 to 7046, and 7054 to 7056.
sub7= column, 1 to 7, 15 to 23, 31 to 39, 47 to 55, .. 7039 to 7047, and 7055 to 7056.
sub8= column, 1 to 8, 16 to 24, 32 to 40, 48 to 56.... 7040 to 7048, and 7056.
sub9= column, 1 to 9, 17 to 25, 33 to 41, 49 to 57................... and 7041 to 7049.
sub10= column, 2 to 10, 18 to 26, 34 to 42, 50 to 58............... and 7042 to 7050.
sub11= column, 3 to 11, 19 to 27, 35 to 43, 51 to 59................ and 7043 to 7051.
sub12= column, 4 to 12, 20 to 28, 36 to 44, 52 to 60............... and 7044 to 7052.
sub13= column, 5 to 13, 21 to 29, 37 to 45, 53 to 61............... and 7045 to 7053.
sub14= column, 6 to 14, 22 to 30, 38 to 46, 54 to 62............... and 7046 to 7054.
sub15= column, 7 to 15, 23 to 31, 39 to 47, 55 to 63............... and 7047 to 7055.
sub16= column, 8 to 16, 24 to 32, 40 to 48, 56 to 64............... and 7048 to 7056.
I appreciate all help and tips.
Thanks in advance!Per Vatsvaghttps://se.mathworks.com/matlabcentral/profile/authors/13287743tag:se.mathworks.com,2005:Question/5736672020-08-01T07:05:47Z2020-08-03T13:48:50ZSame step response for different system When using the function s=stepinfo(sys) to find step response, I receive same values for 3 systems based on Fuzzy PID, Tuned and Untuned PID controllers. The waveforms obtained for the systems are different. The values I keep receiving for the three systems are this.
RiseTime: 0.6769
SettlingTime: 6.8900
SettlingMin: 0
SettlingMax: 2
Overshoot: 550
Undershoot: 0
Peak: 13
PeakTime: 1
The value for systems without controllers and with PI controllers are different.
Kindly help me with this. Mohamed Mhttps://se.mathworks.com/matlabcentral/profile/authors/13218074tag:se.mathworks.com,2005:Question/539092012-11-16T14:28:49Z2020-08-03T13:46:01ZHow can i find the resolution of an image?Hi, how i can find the resolution of an image with matlab (number of pixels in millimeter). thanksCarolehttps://se.mathworks.com/matlabcentral/profile/authors/3699075tag:se.mathworks.com,2005:Question/5728542020-07-30T12:51:44Z2020-08-03T13:45:10ZUnable to add block in Simulink 2016 with add_block commandHi , I'm getting an error when i try to add_block in 2016 MATLAB version with the command listed below
sys = 'Test';
new_system(sys) % Create the model
open_system(sys) % Open the model
% Start adding blocks; for each one the position has to be specified
add_block('built-in/SubSystem',[sys '/xyz'],'Position',[240 95 270 125]);
add_block('built-in/Inport', [sys '/xyz' '/IN1'],'Position',[240 95 270 125]);
add_block('built-in/Inport', ['/Test' '/IN1'],'Position',[140 95 170 125]);
add_line('Test','IN1/1','xyz/1', 'autorouting','on'); Ruhi Phulbandhehttps://se.mathworks.com/matlabcentral/profile/authors/16609803tag:se.mathworks.com,2005:Question/5742522020-08-03T05:39:17Z2020-08-03T13:44:54ZMatlab says solutions are only valid under certain conditions, but when I set ReturnConditions as true, cannot find any solutions. What can I do?I have a system of 12 differential equations and I am trying to find the fixed points using the solve function.
When I run my program, it gives me 130 solutions, but it says:
"Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'."
But when I specify ReturnConditions as true, it says:
"Warning: Unable to find explicit solution. For options, see help."
What can I do to see the conditions? Or can I see which of my 130 solutions are valid without any conditions?
Thanks!
My code for reference:
clear x1 x2 x3 x4 x5 x6 r1 r2 r3 r4 r5 r6 f1 f2 f3 f4 f5 f6 c p alpha beta b
syms x1 x2 x3 x4 x5 x6 r1 r2 r3 r4 r5 r6 f1 f2 f3 f4 f5 f6 c p alpha beta b %all symbols
%now define the ODEs
x1dot = f1*x1 - p*x1*(r1 + beta*r2 + beta*r5);
x2dot = f2*x2 - p*x2*(r2);
x3dot = f3*x3 - p*x3*(r3 + beta*r2);
x4dot = f4*x4 - p*x4*(beta*r2 + r4 + beta*r5);
x5dot = f5*x5 - p*x5*(r5);
x6dot = f6*x6 - p*x6*(beta*r5 + r6);
r1dot = c*(x1*r1/(r1+alpha*r2+alpha*r5)) - b*r1;
r2dot = c*((alpha*x1*r2/(r1+alpha*r2+alpha*r5)) + x2 + (alpha*x3*r2/(r3+alpha*r2)) + (alpha*x4*r2/(alpha*r2+r4+alpha*r5))) - b*r2;
r3dot = c*((x3*r3/(alpha*r2+r3))) - b*r3;
r4dot = c*(x4*r4/(r4+alpha*r2+alpha*r5)) - b*r4;
r5dot = c*((alpha*x1*r5/(r1+alpha*r2+alpha*r5)) + (alpha*x4*r5/(alpha*r2+r4+alpha*r5)) + x5 + (alpha*x6*r5/(alpha*r5+r6))) - b*r5;
r6dot = c*(x6*r6/(alpha*r5+r6)) - b*r6;
%define system of ODEs as the function
fun = [x1dot, x2dot, x3dot, x4dot, x5dot, x6dot, r1dot, r2dot, r3dot, r4dot, r5dot, r6dot];
%To compute the fixed points, solve function == 0
S = solve(x1dot == 0, x2dot == 0, x3dot == 0, x4dot == 0, x5dot == 0, x6dot == 0, r1dot == 0, r2dot == 0, r3dot == 0, r4dot == 0, r5dot == 0, r6dot == 0, 'ReturnConditions',true);
Athulya Ram Sreedharan Nairhttps://se.mathworks.com/matlabcentral/profile/authors/12527625tag:se.mathworks.com,2005:Question/5744202020-08-03T12:20:37Z2020-08-03T13:43:53ZSave the values of a variable inside the DDE23 function for future useHello.
I am using DDE23 to solve a syste of delay equations. Let me use a modified version of the built-in example as a demo:
function ddex1
sol = dde23(@ddex1de,[1, 0.2],@ddex1hist,[0, 5]);
figure;
plot(sol.x,sol.y)
title('An example of Wille'' and Baker.');
xlabel('time t');
ylabel('solution y');
end
function s = ddex1hist(t)
s = ones(3,1);
function dydt = ddex1de(t,y,Z)
ylag1 = Z(:,1);
ylag2 = Z(:,2);
k = ylag1(1)*y(2) + y(1); % <--- This is what I want
dydt = [ ylag1(1) + k
ylag1(1) + ylag2(2)
y(2) ];
I tried to mimic the solution presented here for ODE but to no avail, i.e. i tried to change
function dydt = ddex1de(t,y,Z)
to
function [dydt,k] = ddex1de(t,y,Z)
and then solve the dde as usual with
sol = dde23(@ddex1de,[1, 0.2],@ddex1hist,[0, 5]);
and then solve for k using the function. However, this is where I am lost.
Any help (or other suggested method) would be of great help! Thanks a lot.Reymart Lagunerohttps://se.mathworks.com/matlabcentral/profile/authors/6872894tag:se.mathworks.com,2005:Question/5502632020-06-17T23:42:06Z2020-08-03T13:40:32ZSpecify f coefficient with an integralI am trying to solve a 2 dimensional PDE in a square domain of size L with the PDE toolbox that contains an "f" coefficient of the form:
I have no problem implementing the exponential part. However, I don't know how to access the spatial information of the current solution state.u so I can either create an interpolation of the solution at arbitrary points (x,y) or somehow evaluate the integral numerically. This old question seems to indicate that it might not be possible to create an interpolation of the current solution since the solver only passes certain values of state.u, not the solution for every point.
Still, I thought I would ask to see if there was some way to work around it. I included some code for my definition of "f" below in case it can make things clearer.
function fout = ffunction(location,state)
fout = zeros(1,numel(location.x));
L = 1; %for demonstration purposes
%Somehow create an interpolation of state.u in the domain x:[-L/2, L/2] and y:[-L/2, L/2]. Code below doesn't always create
%an interpolation in the entire domain
uinterp = @(xx,yy)interp2(location.x,location.y,state.u,xx,yy);
for ii = 1:numel(location.x)
fun = @(xx,yy)exp(-sqrt((xx-location.x(ii)).^2+(yy-location.y(ii)).^2));
fout(1,ii) = integral2(uinterp*fun,-L/2,L/2,-L/2,L/2);
end
endRoberto Breneshttps://se.mathworks.com/matlabcentral/profile/authors/5064823