https://jp.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — 新規の質問2020-07-04T07:04:41Ztag:jp.mathworks.com,2005:Question/5592982020-07-04T06:36:21Z2020-07-04T07:04:41ZHow to access array element sequentially in for loop?Hello,
I have 5 dataset:
data1=rand(1,1000)
data2=rand(1,1000)
data3=rand(1,1000)
data4=rand(1,1000)
data5=rand(1,1000)
To run my simulation, I am running a for loops for i=1:200 (running for loops for 200 times) where when i=1, I have to select the 3 data from data1 starting from index 1 to 3, then from data2 I have to select 2 data and similar way way from all the arrays.
I have to select the values sequentially and a non-repetitive way. That means, when i=2, I have to select data from data1 from index 4 to 6.
Then I will use that data in for calculation. Like, result would be:
result = data1(index1) + data2(index1);
result2=data1(index2) + data2(index2);
at the end of the simulation, I will have result vaules that contains 200 data.
Thank you so much for your time and considerations.
Tania Islamhttps://jp.mathworks.com/matlabcentral/profile/authors/14515142-tania-islamtag:jp.mathworks.com,2005:Question/5593072020-07-04T07:01:06Z2020-07-04T07:02:06ZHow to print several matrices with different dimensions from a single line of code?Input (randomly chosen):
A=ones(4);
B=magic(5);
C=hilb(6);
Is there an easy method to print all of the matrices from a single line of code (instead of leaving those semi colons off)? Please note that I do not want them manipulated and/or concatenated in any way.
Desired output for the above input is given here (obtained here, by leaving the semi colons off):
Aryan Ritwajeet Jhahttps://jp.mathworks.com/matlabcentral/profile/authors/14314830-aryan-ritwajeet-jhatag:jp.mathworks.com,2005:Question/5593012020-07-04T06:38:54Z2020-07-04T07:01:02Zmerging date and time columns in a timetableI have .csv file with two separate columns one for date and one for time. I am trying to import them both in a single field in a timetable and use them as rowtimes. Any pointers?
Date Time
____ ______
06/07/2020 17:00:01
06/07/2020 17:00:02
06/07/2020 17:00:03
Akram Husseinhttps://jp.mathworks.com/matlabcentral/profile/authors/18649540-akram-husseintag:jp.mathworks.com,2005:Question/5586982020-07-02T23:12:36Z2020-07-04T06:59:22ZHow do I set a seed to generate different random initial numbers and storing themfor kk = 1 : Iter
xD = rand(N,1)*2*pi; % Init Cond. Driver
endSamsonhttps://jp.mathworks.com/matlabcentral/profile/authors/14635796-samsontag:jp.mathworks.com,2005:Question/5593042020-07-04T06:54:02Z2020-07-04T06:55:36Zi have downloaded the "trial version" but still it asking for the activation key.so,from where i can get it.......NAVishal Patilhttps://jp.mathworks.com/matlabcentral/profile/authors/18271020-vishal-patiltag:jp.mathworks.com,2005:Question/5592472020-07-04T01:22:51Z2020-07-04T06:52:48Zfast fourier tranform gives unequals amplitudes for frequencies with initially (before the fft) the same amplitudeHi, I tried to find all the different frequencies in a sums of sinus using the fast fourier transform function in MATLAB. The fft function gives me the right frequencies, but with differents amplitude, even if all the amplitudes are equal to 1 (see the y vector). I really dont understand what im doing wrong. Thanks you very much for any information, don't hesitate to ask if you need more details about the question.
Here is the code I ran :
f = 3*10^6; %sampling frequency
t = 0:f^-1:1*10^-2-1*f^-1; %time vector
y = sin(2*pi*(1000*10^-9)^-1*t) + sin(2*pi*(1300*10^-9)^-1*t) + sin(2*pi*(900*10^-9)^-1*t) + sin(2*pi*(800*10^-9)^-1*t) + sin(2*pi*(700*10^-9)^-1*t) ;
Y = fft(y, 2^nextpow2(length(t)));
Amp = Y.*conj(Y)/length(Y);
frequ = f/length(Y)*(0:length(Y)/2);
plot(frequ,Amp(1:(length(Y))/2+1))Henri Paquettehttps://jp.mathworks.com/matlabcentral/profile/authors/13568334-henri-paquettetag:jp.mathworks.com,2005:Question/5592892020-07-04T06:12:29Z2020-07-04T06:41:45ZError while Diagonalizing the Matrix I'm studying State Space function thesedays, and made a code below
A = [ 0 1 0; 0 0 1; -6 -11 -6];
P = [ 1 1 1; -1 -2 -3; 1 4 9 ];
S = P^(-1);
A1 = S*A*P;
Expected answer was
A1 = [ -1 0 0 ; 0 -2 0 ; 0 0 -3 ]
because of the eigenvalue process, however, it made a conclusion as
A1 = [ -1, -1.7764e-15, -2.6645e-15 ; 2.6645e-15, -2, 7.1054e-15 ; -1.3323e-15, -2.6645e-15, -3 ]
And other variables are calculated just as I expected.
I don't know what makes this kind of error and how can I solve it?
It can be a critical error in the process.Kang san Leehttps://jp.mathworks.com/matlabcentral/profile/authors/11597699-kang-san-leetag:jp.mathworks.com,2005:Question/5592952020-07-04T06:16:51Z2020-07-04T06:37:39ZHow can I open the Matlab due to the fatal error.After i tried to install some stuffs from math works?waleed khaledhttps://jp.mathworks.com/matlabcentral/profile/authors/15119831-waleed-khaledtag:jp.mathworks.com,2005:Question/5105062020-03-12T10:47:12Z2020-07-04T06:37:23ZFinding distance between two curves at diffrent points1.Suppose the curves are defined, how do i find the distance between two curves at diffrent points.
Curve 1= f(x)
curve 2 = g(x)
Do i need to define points on one of the curve to find out the required distance???
For exmple I am posting an image.
Important note-
I need distance at diffrent points between two curves and not single point nor am I looking for minimum distance between curves.
Perpendicular distance from tangent as shown in image.Praveen Patnaikhttps://jp.mathworks.com/matlabcentral/profile/authors/17640651-praveen-patnaiktag:jp.mathworks.com,2005:Question/5588242020-07-03T05:58:59Z2020-07-04T06:35:26ZHelp Needed for the following coding problemSo I have a problem at hand. I have few differential equations which are interdepent on one another. I have a written code with the following workflow :
1) I define intial conditions pretaining to the Vectors that I'll be using.
2) I run a for loop based on those on initial condtions for the differential equation
3) I apply Ode45 to the result to solve the differential equation and then send the values back to the starting point taking that as inital conditon and repeat this for say 40 steps.
I am facing the following errors -
1) My Ode45 solver doesn't work and I get 0 values as the updated final values.
2) If I go for a Multidimensional ode45 solver becasue I have like 8 D.E to be solved, it just doesn't work. I have attached a sample code and a sample image for reference.
Thanks for the help!
clc;
clear all;
close all;
N = 6;
P = [1 2 1 2 3 1; 1 2 2 1 1 3];
Distance = zeros(N,N);
for i = 1:N
Distance(:,i) = sqrt(((P((2*i)-1)-P(1:2:(2*N-1))).^2)+((P(2*i)-P(2:2:(2*N))).^2)); %Distance between All Agents
end
Z = Distance < 3;%-eye(N)
A_undir = Z; %adjacency Matrix
D_undir = diag(sum(A_undir,1)); %Degree Matrix (Out-Degree)
L_undir = D_undir - A_undir;
Raidus = 0.5;
sigma = Raidus/2;
episilon = 0.5;
psi = 0.8;
epsilion_tilda = episilon + psi;
k1 = 1.5;
k2 = 0.15;
k3 = 1.5;
k4 = 0.0001;
kp = 6;
ki = 2;
k=5;
gamma = 1.5;
z1_dot = zeros(1,N);
z2_dot = ones(1,N);
w1_dot = zeros(1,N);
w2_dot = zeros(1,N);
z1 = zeros(1,N);
w1 = zeros(1,N);
z2 = zeros(1,N);
w2 = zeros(1,N);
Lambda2 = zeros(1,N);
Del_lambda_tilda = zeros(1,N);
V2_tilda = [1 1 1 1 1 1];
V2_tilda_dot = zeros(1,N);
alpha1 = V2_tilda;
alpha2 = (V2_tilda).^2;
A = A_undir;
U_c = zeros(2,N);
U_e = zeros(2,N);
P_dot = zeros(2,N);
Beta = Distance < 2;
Norm_Matrix = (Beta.^2)/(2*(sigma^2));
Po_x = zeros(N,N);
Po_y = zeros(N,N);
sumz1_1=z1.'-z1;
sumz1 = (sum(sumz1_1,2))';
sumw1_1=w1.'-w1;
sumw1 = (sum(sumw1_1,2))';
sumz2_2=z2.'-z2;
sumz2 = (sum(sumz2_2,2))';
sumw2_2=w2.'-w2;
sumw2 = (sum(sumw2_2,2))';
sumv2_tilda_1 = V2_tilda.'-V2_tilda;
sumv2_tilda = (sum(sumv2_tilda_1,2))';
sum_adjacency = (sum(A,2))';
for i = 1:N
z1_dot(:,i) = gamma*(alpha1(:,i)-z1(:,i))-kp*sumz1(:,i)+ki*sumw1(:,i);
w1_dot(:,i) = -ki*sumz1(:,i);
z2_dot(:,i) = gamma*(alpha2(:,i)-z2(:,i))-kp*sumz2(:,i)+ki*sumw2(:,i);
w2_dot(:,i) = -ki*sumz2(:,i);
V2_tilda_dot(:,i) = -(k1*z1(:,i))-(k2*sum_adjacency(:,i)*sumv2_tilda(:,i))-(k3*(z2(:,i)-1)*V2_tilda(:,i))-(k4*abs(V2_tilda(:,i)).*V2_tilda(:,i));
Lambda2(:,i) = k3*(1-z2(:,i))/k2;
%Defining Position Matrix Based on P(i) - P(j)
Po_x(:,i) = (P((2*i)-1)-P(1:2:(2*N-1))) ;
Po_y(:,i) = + (P(2*i)-P(2:2:(2*N)));
Del_lambda_tilda = -sum_adjacency(:,i)*sumv2_tilda(:,i)*([Po_x(i,:); Po_y(i,:)]).*(1/sigma)^2; %Replace 1 with Position
A = exp(-Norm_Matrix);
U_c(:,i) = ((csch(Lambda2(:,i)-epsilion_tilda)).^2)*Del_lambda_tilda(:,i);
U_e(:,i) = [k*cos(2*pi/N+1)*i k*sin(2*pi/N+1)*i]';
P_dot(:,i) = U_c(:,i) + U_e(:,i);
end
t_initial = 0;
t_final = 100;
x_initial1 = zeros(1,N)';
x_initial2 = zeros(1,N)';
x_initial3 = zeros(1,N)';
x_initial4 = zeros(1,N)';
x_initial5 = ones(1,N)';
x_initial6 = P(end-1,:)';
x_initial7 = P(end,:)';
[t,z1_solver] = ode45(@(t,z1_solver) z1_dot',[t_initial t_final],x_initial1);
[t,w1_solver] = ode45(@(t,w1_solver) w1_dot',[t_initial t_final],x_initial2);
[t,z2_solver] = ode45(@(t,z2_solver) z2_dot',[t_initial t_final],x_initial3);
[t,w2_solver] = ode45(@(t,w2_solver) w2_dot',[t_initial t_final],x_initial4);
[t,V2_tilda_solver] = ode45(@(t,V2_tilda_solver) V2_tilda_dot',[t_initial t_final],x_initial5);
[t,P_dot_solver] = ode45(@(t,P_dot_solver) P_dot(end-1,:)',[t_initial t_final],x_initial6);
[t,P_dot1_solver] = ode45(@(t,P_dot1_solver) P_dot(end,:)',[t_initial t_final],x_initial7);
z1 = z1_solver(end,:);
w1 = w1_solver(end,:);
z2 = z2_solver(end,:);
w2 = w2_solver(end,:);
V2_tilda = V2_tilda_solver(end,:);
Position1 = P_dot_solver(end,:);
Position2 = P_dot1_solver(end,:);
P = [Position1 ; Position2];
Pranjal Bhatiahttps://jp.mathworks.com/matlabcentral/profile/authors/10746478-pranjal-bhatiatag:jp.mathworks.com,2005:Question/5473982020-06-12T23:29:00Z2020-07-04T06:33:00Zcalculation of histogram only from the foregroundHi,
I am stuck with this idea and code for the past three months, I have tried n number of codes but all was a failure. I would like to calculate the histogram only from the foreground image, and I have to split the histogram into two one below the middle value and one part above the middle value, all this has to be done without including the background. I am attaching my image with my code please do help with the code. I have also asked in this forum in different ways, but none of the help worked in my project, so I requesting to have a correction of my code. Malini Bakthavatchalamhttps://jp.mathworks.com/matlabcentral/profile/authors/17650448-malini-bakthavatchalamtag:jp.mathworks.com,2005:Question/5592022020-07-03T22:17:20Z2020-07-04T06:32:48Zcreate 5 minute bar intervals of time dataI have a csv file with price data and it is organized in date in MM/dd/yyyy and time in HH:mm:ss. The data is in 1 second intervals. I am trying to create specific intervals of that data let's say 5 minute intervals and read the prices at that time and plot a bar chart.
However, in trying to do so I found the data maybe missing few seconds here and there. So what is the best way to get something like
date Time Price
7/3/2020 17:00:00 452
7/3/2020 17:05:00 430
7/3/2020 17:10:00 444Akram Husseinhttps://jp.mathworks.com/matlabcentral/profile/authors/18649540-akram-husseintag:jp.mathworks.com,2005:Question/5550282020-06-26T05:39:41Z2020-07-04T06:32:43Zroi mask and working on the masked image Hi, I am working on a project, where i have to work with only the foreground, not the background, so iused color threshold, image segment app nothing worked, so finally i made a transparent background in alpha layer and stored the image usng imwrite. Now for my foreground analysis, i used the saved image but it calculates including transparent backgroun. I tried to use the imfreehand roi , i am able to make the roi, but cannot use the masked ROI for my further analysis. Even i freehand roi is not exactly masking the foreground, there are some features that missing. so i used this below mentioned code
img = double(imread('alphaimg1.png'))/255;
imshow(img);
ROI = imfreehand;
img_mask = ROI(ROI ~=1)
Maximg = max(img_mask); % trying to find the max value of the roi image
Minimg = min(img_mask); % trying to find the max value of the roi image
hist(img_mask,0:0.01:1)
medMask = median(img_mask);
imshow(medMask)
It shows the following error
img_mask =
imfreehand with properties:
Deletable: 1
Error using max
Invalid data type. First argument must be numeric or logical.
Error in alphaimgtrial1 (line 54)
Maximg = max(img_mask); % trying to find the max value of the roi image
using this ROI, i have find median pixel value of the image and try to split the histogram like dark pixels less than median value set to median value and light pixels higher than median value set to median value.
How do I proceed? I am attaching an alpha layer transparent image. Malini Bakthavatchalamhttps://jp.mathworks.com/matlabcentral/profile/authors/17650448-malini-bakthavatchalamtag:jp.mathworks.com,2005:Question/5583822020-07-02T12:15:24Z2020-07-04T06:31:17Z'inpolygon' returns zeros logical variable (R2019b, Win10)Hi,
I try to make a mask for area of ocean's basin using function inpolygon.
I have a big area with latitude from 66° to 73° (length is 420) and longitude from -5° to 18° (length is 1380):
lat = linspace(66,73,420)'; % latitude
lon = linspace(-5,18,1380)'; % longitude
[LAT,LON] = ndgrid(lat,lon); % 2-D matrix
Next, I use contourf to plot bathymetry ('z' has 420x1380 size) and choose mask border with mouse (polygon vertices):
contourf(lon,lat,z) % bathymetry
[xi,yi] = getpts(gca); % choose mask border
xi = [xi; xi(1)]; yi = [yi; yi(1)];
hold on
plot(xi, yi,'k','LineWidth',2) % polygon (mask)
So i get something like this:
Finally, I use inpolygon to check what points (grid nodes - LAT and LON) belong to this polygon. But there is no 'true' points inside (variable 'check' is zero).
mask = inpolygon (LAT, LON, xi, yi);
check = sum(sum(mask))
Anyone have any ideas how to fix this?
Elena Novoselovahttps://jp.mathworks.com/matlabcentral/profile/authors/13716409-elena-novoselovatag:jp.mathworks.com,2005:Question/5592922020-07-04T06:13:19Z2020-07-04T06:13:19Zhomeインストール時にネットワークエラー見つからないファイル esd.mathworks.com と表示されインストールできません。youhei natsumehttps://jp.mathworks.com/matlabcentral/profile/authors/12708761-youhei-natsumetag:jp.mathworks.com,2005:Question/5592832020-07-04T05:21:03Z2020-07-04T06:13:12ZHow to detect the uitable on GUII wnat to detect whether the uitable on the GUI is empty.
but it shows "Input #2 expected to be a cell array, was double instead."
If I change the data format to cell, it will not be able to enter "all(cellfun(@isempty, data(:)))"
data = get(handles.uitable1);
if all(cellfun(@isempty, data(:)))
errordlg('uitable is empty','warning');
else
disp('not empty');
end
how modifity it?han hanhttps://jp.mathworks.com/matlabcentral/profile/authors/13769741-han-hantag:jp.mathworks.com,2005:Question/5591692020-07-03T20:43:43Z2020-07-04T06:06:37ZHow to make a structure to be input of a function and then its updated version to be output of the function?I want to make a structure to be input of a function and then do some analysis and add some fields to the structure and return the updated version of structure as the ouput of the function. I tried to use:
struct=function updatestruct(struct,...)
end
and it did not update the sruct and produced a new strucutre at the output loosing the previously stored data in the struct.Zeynab Mousavikhamenehttps://jp.mathworks.com/matlabcentral/profile/authors/14179884-zeynab-mousavikhamenetag:jp.mathworks.com,2005:Question/5574792020-06-30T23:13:10Z2020-07-04T06:05:59Zi just installed matlab and simulink,windows 2020a version.when i open it works slow and the laptop hangs.why?my laptop is new (8gb ram)the application is not working properly and is slow.why?Kushal Gowdahttps://jp.mathworks.com/matlabcentral/profile/authors/18119874-kushal-gowdatag:jp.mathworks.com,2005:Question/4790252019-09-05T12:02:21Z2020-07-04T06:04:22ZRegarding matlab cody solutionsI have very basic knowledge in matlab programming. So, I decided to improve my matlab programming knowledge by doing some Matlab Cody exercises. As I'm a beginner in Matlab Programming, I couldn't able to solve more than 10 problems in Matlab Cody. I have tried to look at others soultions . Unfortunately , I cannot see others solutions. I cannot even see the solutions of others for the problems that I have already solved. Then what is the purpose of Cody when you cannot improve your coding by looking at various possibilities of solutons from others. It really didn't make any sense for me . Can somebody tell me the way to improve my coding knowledge in matlab? nagasai thumatihttps://jp.mathworks.com/matlabcentral/profile/authors/13849900-nagasai-thumatitag:jp.mathworks.com,2005:Question/5592682020-07-04T04:41:12Z2020-07-04T05:54:13Z3D-Surface between 2 lines.Hi all,
Previously with one of the Mathwork community users' (darova) suggestion we created 3D surfaces on the sphere.
Please find the script below.
Here I have 3 surfaces the one of which (green) is below the other 2 surfaces.
Now, I aim to fill the gap between the top (red) and bottom (green) surfaces by creating an additional surface (i.e. an oblique surface (a slightly tilted surface)).
To make it clearer, in the output image of the attached code one can see 2 lines between the top (red) and bottom (green) surfaces.
I aim to create a surface between those 2 lines in order to close the gap.
I've tried several ways, and also a triangulation method, however, was not successfull.
Could you please make a suggestion on this.
I appreciate the time you spend.
Regards
l1 = [-3.53 -3.16 -3.543 -3.359];
l2 = [-3.16 -3.16 -3.359 -2.807];
l3 = [-3.16 -3.846 -2.807 -2.518];
l4 = [-3.846 -3.925 -2.518 -3.254];
l5 = [-3.925 -3.53 -3.254 -3.543];
ll1 = [-4.05 -4.690 -3.274 -3.395];
ll2 = [-4.690 -4.479 -3.395 -2.728];
ll3 = [-4.479 -4.347 -2.728 -2.597];
ll4 = [-4.347 -3.978 -2.597 -2.545];
ll5 = [-3.978 -4.05 -2.545 -3.274];
c1 = [-4.03 -3.966 -3.229 -2.532];
c2 = [-3.966 -3.872 -2.532 -2.545];
c3 = [-3.872 -3.932 -2.545 -3.229];
c4 = [-3.932 -4.03 -3.229 -3.229];
xl1 = [l1(1) l1(2) l2(2) l3(2) l4(2) l1(1)];
yl1 = [l1(3) l1(4) l2(4) l3(4) l4(4) l1(3)];
xl2 = [ll1(1) ll1(2) ll2(2) ll3(2) ll4(2) ll1(1)];
yl2 = [ll1(3) ll1(4) ll2(4) ll3(4) ll4(4) ll1(3)];
xf = [c1(1) c1(2) c2(2) c3(2)];
yf = [c1(3) c1(4) c2(4) c3(4)];
rf = 6.8;
gd1 = [2;length(xl1);xl1(:);yl1(:)];
dl1 = decsg(gd1);
[p1,e1,t1] = initmesh(dl1,'hmax',0.2);
z1 = sqrt(49 - p1(1,:).^2 - p1(2,:).^2);
ff1.vertices = [p1' z1(:)];
ff1.faces = t1(1:3,:)';
gd2 = [2;length(xl2);xl2(:);yl2(:)];
dl2 = decsg(gd2);
[p2,e2,t2] = initmesh(dl2,'hmax',0.2);
z2 = sqrt(49 - p2(1,:).^2 - p2(2,:).^2);
ff2.vertices = [p2' z2(:)];
ff2.faces = t2(1:3,:)';
gdf = [3;4;xf(:);yf(:)];
dlf = decsg(gdf);
[pf,ef,tf] = initmesh(dlf,'hmax',0.2);
zf = sqrt(47.5 - pf(1,:).^2 - pf(2,:).^2);
ff3.vertices = [pf' zf(:)];
ff3.faces = tf(1:3,:)';
[x,y,z] = sphere(20);
surf(7*x,7*y,7*z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xl1,yl1,'linew',2)
h1 = patch(ff1,'facecolor','b');
hold on
%[x,y,z] = sphere(20);
surf(7*x,7*y,7*z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xl2,yl2,'linew',2)
h2 = patch(ff2,'facecolor','r');
hold on
%[x,y,z] = sphere(20);
surf(7*x,7*y,7*z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xf,yf,'linew',2)
hf = patch(ff3,'facecolor','g');
xfl = [-4.0300 -4.0500 -3.966 -3.978];
yfl = [-3.2290 -3.2740 -2.532 -2.545];
zfl = [zf(1) z2(5) zf(2), z2(4)];
hline1=plot3(([xfl(1) xfl(2)]),([yfl(1) yfl(2)]),([zfl(1) zfl(2)]),'k');
hline2=plot3(([xfl(3) xfl(4)]),([yfl(3) yfl(4)]),([zfl(3) zfl(4)]),'k');
hold on
set(hline1,'linewidth',2)
set(hline2,'linewidth',2)
Mammadbaghir Baghirzadehttps://jp.mathworks.com/matlabcentral/profile/authors/16688975-mammadbaghir-baghirzadetag:jp.mathworks.com,2005:Question/5592382020-07-04T00:36:27Z2020-07-04T05:44:09ZTrying to create a set of matrixes using a for loop. I have an error on line 23: Array indices must be positive integers or logical values. Basically making matrixes labeled ke1, ke2, ke3...clear all;close all;clc;
E=230*10^9; %Pa (young's modulus of the steel truss members)
A=20*10^-4; %m^2 (cross sectional area of truss members)
%7 elements
%5 nodes with 2 degrees of freedom each so {d} will be a 10*1 matrix
%also {f} will be 10*1 and [K] will be 10*10
%hooke's law -> F=AE(lf-li)/l
%spring constant -> k=AE/l
le=[5;1.5;1.5;5;3;(sqrt((1.5^2)+(5^2)));(sqrt((1.5^2)+(5^2)))]; %lengths of elements
k=A*E./le; %spring constants of each element
%if [K] is a 10*10 matrix
%each elemental stiffness matrix will be 4x4 because there are 2 nodes and
%2 degrees of freedom for each element
thetae=[0;pi/2;pi/2;0;pi/2;atan(1.5/5);atan(-1.5/5)];
c=cos(thetae);
s=sin(thetae);
for i=[0;pi/2;pi/2;0;pi/2;atan(1.5/5);atan(-1.5/5)]
ke(i)=[c(i)^2,c(i)*s(i),-c(i)^2,-c(i)*s(i);
c(i)*s(i),s(i)^2,-c(i)*s(i),-s(i)^2; %elemental global stiffness matrix
-c(i)^2,-c(i)*s(i),c(i)^2,c(i)*s(i);
-c(i)*s(i),-s(i)^2,c(i)*s(i),s(i)^2;];
endJONATHAN DAVID JR FREEMANhttps://jp.mathworks.com/matlabcentral/profile/authors/16354950-jonathan-david-jr-freemantag:jp.mathworks.com,2005:Question/5592862020-07-04T05:41:48Z2020-07-04T05:41:48ZHow to solve a non linear 3rd order differential equationHi, I need to solve a 3rd order, non linear differential equation. I would preferably like a symbolic solution for the equation, as this equation is the input for another script. The equation is as follows:
where m is a constant (for my purposes, m =1)
f is a function of variable eta, and the initial conditions are as follows:
;
;
and
I tried using the code mentioned below, but it is unable to give me a symbolic solution. Can anybody please help me solve this problem?
m = 1;
syms f(eta)
Df = diff(f,eta);
D2f = diff(f,eta,2);
ode = diff(f,eta,3)+0.5*(m+1)*f*D2f+m*(1-Df^2) == 0;
cond1 = f(0) == 0;
cond2 = Df(0) == 0;
cond3 = D2f(10^100) == 1;
conds = [cond1 cond2 cond3];
uSol(eta) = dsolve(ode,conds)Sumedh Somanhttps://jp.mathworks.com/matlabcentral/profile/authors/17362344-sumedh-somantag:jp.mathworks.com,2005:Question/2484982015-10-14T01:10:21Z2020-07-04T05:32:49ZHow to upload Matlab program to Raspberry Pi 2 and execute it in the Raspberry Pi directly ? is it even possible ? I am currently doing my final year project and I have been asked to develop a program in Matlab simulink and then upload the program into the Raspberry Pi 2 so It would be acting as a standalone device. The nature of my program is image processing.Hatefhttps://jp.mathworks.com/matlabcentral/profile/authors/4380565-hateftag:jp.mathworks.com,2005:Question/5592742020-07-04T05:00:47Z2020-07-04T05:32:18Z実行しているファイルのパスの取得に関してMATLABでmlxやmファイルを実行する際，そのファイルがあるディレクトリの場所に移動してから実行しようと考えております．
ディレクトリの移動には，
cd(PATH)
を使用すればよいことは分かるのですが，mlxやmファイルが存在する場所をどのように確認すればよいでしょうか？
また，cdコマンドは実行するmlxファイルやmファイルに記述することを考えております．Teppei Iwatahttps://jp.mathworks.com/matlabcentral/profile/authors/16021890-teppei-iwatatag:jp.mathworks.com,2005:Question/5581962020-07-02T07:01:39Z2020-07-04T05:28:48ZHow to start a third party application with Matlab?Hi everyone,
My Matlab script generates some files, when I compile it. I need to load this files in to a another third-party application. Instead of manually doing this, I would like to automate the process with a function. Could someone please tell me, is there any way to do this?My goal is to first open the application and then load the files using File->Newproject with a Matlab command.
Thanks in advanceRaja Vardhan Reddy Kothakapuhttps://jp.mathworks.com/matlabcentral/profile/authors/8973029-raja-vardhan-reddy-kothakaputag:jp.mathworks.com,2005:Question/5592652020-07-04T04:30:09Z2020-07-04T05:21:18ZDownloading text files from Matlab causes them to be corruptedFrom my matlab program, I have saved a number of variables (128x128 matrices) as text files. When I open them on matlab itself (Matlab online r2020a), they open fine and display the numeric data I want. However when I download them, either individually or in bulk as a zip file, the .txt files display only junk values, when opened in Notepad. Why could this be happening and what is the fix?
Attaching a screenshot of the files viewed in program, and after download:
Pranav Krishnanhttps://jp.mathworks.com/matlabcentral/profile/authors/17897042-pranav-krishnantag:jp.mathworks.com,2005:Question/5577282020-07-01T11:52:17Z2020-07-04T05:17:04ZProgram working on one PC but not on otherIn a program to calculate value at risk. The for loop is stuck on a particular iteration 41 out of 50 iterations. But on some machines it is working fine.
Is there a problem of memory allocation or something else?
The error is coming is following function
function z2 = myfunction(r1,x1,x2)
warning('off', 'stats:gpfit:EvalLimit');
[bootstat,bootsam] = bootstrp(50,[],r1); %Sampling With Replacement from r1
Z=sort(r1(bootsam));% bootsam is the indices and Z1(bootsam) is 50 sample drawn
temp = [];
for k1 = x1:.1:x2
a5=0;
for i = 1:50
y5=Z(:,i);
[f12,x12]=ecdf(y5);
f12=f12(2:end);
x12=x12(2:end);
k11=k1;
k1 = min(k1,(y5(end-500))); % this is due to the possibility that the threshold could be greater than y(end-500)
% at least 500 observations are required to calculate Non-subjective Value-at-Risk
y5(y5<=k1)=[];
para = gpfit(y5-k1);
[h7, h8] = size (y5>k1);
h4=min(find(y5>k1));
[h5, h6] = size (y5);
s5=0;
clear F1 F2 F3 g;
for j5=h4:h5
F1=1-interp1q(x12,f12,y5(j5));
F2=1-interp1q(x12,f12,k1);
F3 = F1/F2;
g = 1-gpcdf(y5(j5)-k1,para(1), para(2), 0);
s5=s5+(g-F3)^2;
end
a5=a5+(s5/h7);
end
temp = [temp; [k1 a5]];
k1=k11;
end
[M,I]= min(temp(:,2));
z2=temp(I,1);
endNikhil Guptahttps://jp.mathworks.com/matlabcentral/profile/authors/18583886-nikhil-guptatag:jp.mathworks.com,2005:Question/5561622020-06-28T17:30:40Z2020-07-04T05:08:59ZHow to create an underline in textGiven ist following legend:
legend('Group 6 MHz \newline{\bff_1} \newline2f_2-f_3 \newlinef_2+f_3-f_4 ', ...
'\newlineGroup7.3 MHz \newline{\bff_2} \newline2f_3-f_4 \newlinef_1+f_3-f_2 \newlinef_1+f_4-f_3 ', ...
'\newlineGroup8.7 MHz \newline{\bff_3} \newline2f_2-f_1 \newlinef_2+f_4-f_3 \newlinef_1+f_4-f_2 ', ...
'\newlineGroup10 MHz \newline{\bff_4} \newline2f_3-f_2 \newlinef_2+f_3-f_1 ','location','northeastoutside')
A total of four graphs with corresponding sub-labels are to be shown here. I want the first line (Group 6 MHz, Group7.3 MHz ...) to be underlined. Does somebody has any idea?
Many thanks!Mepehttps://jp.mathworks.com/matlabcentral/profile/authors/12417523-mepetag:jp.mathworks.com,2005:Question/5557902020-06-27T16:37:27Z2020-07-04T05:07:00ZSave data to Excel without overlappingA, a 3x2 variables that store 3 points detected.
B, variable to store angle of that 3 points.
A and B is in a for loop, since I detect many frames (around 400 frames).
How can I store A and B for all frames in two different excel files.
Excel filename for A: Coordinates.xlsx, B: Angle.xlsxTeo Chou Wenhttps://jp.mathworks.com/matlabcentral/profile/authors/16811728-teo-chou-wentag:jp.mathworks.com,2005:Question/5592802020-07-04T05:05:40Z2020-07-04T05:05:40ZHow do I design create .ssc compoenentHello All,
I'm trying to write and ssc component for bi directional buck boost converter,which allows the current(power) to flow on either sides depending on the conditions.Hence,when I connect two batteries using a converter in between,the converter should be able to charge and discharge both the batteries depending on the inout conditions .It is working fine for side1 but not for side2.What could be the cause for error .Kindly help
component Boost_DifferentialRef
% Boost_DifferentialRef
nodes
p1=foundation.electrical.electrical; % 1+:top
n1=foundation.electrical.electrical; % 1-:top
p2=foundation.electrical.electrical; % 2+:bottom
n2=foundation.electrical.electrical; % 2-:bottom
end
inputs
% Vcontrol={0,'1'}; % Control:bottom
FailureMode={ 1, '1' } % Failure mode: top
Source_at_1={ 1, '1' } % Source1: top
Source_at_2={ 1, '1' } % Source2: top
end
outputs
Status={1,'1'}; % Status :bottom
end
parameters
Efficiency ={ 0.9, '1' };% Power Efficiency
% Vout={28,'V'}; % Output Voltage
DC_required={ 540, '1' };% Voltage regulation
VoltageError={ 1e-3, '1' }; % Voltage error
end
parameters(Hidden=true)
Kc={1,'A'};
Kv={1,'V'};
end
variables
ip1 = { 0, 'A' }; % input Current1
v1 = { 0, 'V' }; % input Voltage1
in1 = { 0, 'A' }; % input Current2
v2 = { 0, 'V' }; % input Voltage2
in2 = { 0, 'A' }; % output Current2
v4 = { 0, 'V' }; % output Voltage2
v3={0,'V'}; % output Voltage1
ip2= { 0, 'A' }; % output Current1
% idc = { 0, 'A' }; % output Current
Pin= { 0, 'W' }; % Input power
Pout = { 0, 'W' }; % output power
Losses={ 0, 'W' }; % power loss
end
variables(Access=protected)
Eff ={ 1, '1' };
M= { 1, '1' }; % ratio
end
branches
ip1 : p1.i->*;
in1 : n1.i -> *;
ip2 : p2.i-> *;
in2: n2.i-> *;
end
equations
v1 == p1.v ;
v2 == n1.v ;
v3 == p2.v ;
v4 == n2.v ;
if FailureMode>0 && Source_at_1 == 1 && abs(v1)> 0.1*Kv
v3 == Kv*(DC_required)/2;
v4 == -Kv*(DC_required)/2;
M==abs((v3-v4)/(v1-v2));
ip1 == -ip2*M;
in1 == -in2*M;
Pin == v1*ip1;
Pout== Efficiency *Pin
Eff== Efficiency;
Losses==Pin*(1-Efficiency);
Status==1;
elseif FailureMode>0 && Source_at_2 == 1 && abs(v3)> 0.1*Kv
v1 == Kv*(DC_required)/2;
v2 == -Kv*(DC_required)/2;
M == abs((v1-v2)/(v3-v4));
ip2 == -ip1*M;
in2 == -in1*M;
Pin==(v3)*(ip2);
Pout== Efficiency *Pin
Eff== Efficiency;
Losses==Pin*(1-Efficiency);
Status==1;
else
v1==0;
v2==0;
M==0;
ip1 ==0;
in1 ==0;
Pin==0;
Pout== 0;
Eff== Efficiency;
Losses==0;
Status==0;
end
% idc==abs(i3);
end
end
Sushma nhttps://jp.mathworks.com/matlabcentral/profile/authors/12689439-sushma-ntag:jp.mathworks.com,2005:Question/5592772020-07-04T05:03:33Z2020-07-04T05:03:33ZHow to solve this fourier series/ boundary value on matlab?Can anyone tell me how to compute this on matlab? show the codes in step etc...
Suhayl Mlbhttps://jp.mathworks.com/matlabcentral/profile/authors/18911145-suhayl-mlbtag:jp.mathworks.com,2005:Question/5592712020-07-04T04:55:34Z2020-07-04T04:55:34ZCan we solve time dependent non-linear PDE using solvepde?I tried the following code to solve time depenedent non linear pde but I am not getting the convergence.
The coefficient c is sqrt(1+ux^2+uy^2) and the exact solution I am taking is u= x*y*(x-1)*(y-1) corresponding We can find f which is a function of x,y and t.
model = createpde(1);
R1 = [3;4;0;1;1;0;0;0;1;1];g=decsg(R1);
geometryFromEdges(model,g);
pdegplot(model,'EdgeLabels','on');
xlim([0,1]);
ylim([0,1]);
axis equal
applyBoundaryCondition(model,'dirichlet','Edge',1:4,'u',0);
setInitialConditions(model,0);
specifyCoefficients(model,'m',0,'d',1,'c',@ccoeffunction,'a',0,'f',@fcoeffunction);
mesh = generateMesh(model,'Hmax',0.125,'GeometricOrder','linear');model.SolverOptions.MaxIterations = 30; model.SolverOptions.ResidualNorm =Inf ;model.SolverOptions.ReportStatistics = 'on';
tlist = linspace(0,1,17);
results = solvepde(model,tlist);
u = results.NodalSolution;
pdeplot(model,'XYData',u(:,17),'ZData',u(:,17))RAVINA SHOKEENhttps://jp.mathworks.com/matlabcentral/profile/authors/13593494-ravina-shokeentag:jp.mathworks.com,2005:Question/5591032020-07-03T17:33:17Z2020-07-04T04:49:32ZHow to read a multiframe tiff in MATLAB?Hello,
I am trying to read a multiframe tiff of dimension 610 x 610 x 1200
Using imread('file.tiff') reads only the first image as mentioned in the documentation.
I would like to know how to read all frames.
ip = imread('file.tiff')
i.e
size(ip) = 610 610
but I want it to return
size(ip) = 610 610 1200Deepa Maheshvarehttps://jp.mathworks.com/matlabcentral/profile/authors/8575091-deepa-maheshvaretag:jp.mathworks.com,2005:Question/5592052020-07-03T22:59:21Z2020-07-04T04:27:34ZDon't simplify while using 'latex'Hey, each time I use Matlabs fabulous latex function the term automatically becomes simplified. However, sometimes I want to emphasize some expression that get reduced by the simplification. So: How to surpress it? Niklas Kurzhttps://jp.mathworks.com/matlabcentral/profile/authors/18516014-niklas-kurztag:jp.mathworks.com,2005:Question/5592622020-07-04T04:24:02Z2020-07-04T04:24:02ZHow to show original values in the heatmap and in the colorbar while log(data) is used to make heatmap?Here is the heatmap code:
heatmap(x,y,log(ave_array));
I want the values shown on the heatmap subspace NOT be in log scale and be their original value. Also the same for color bar: to show the original value.
How can I do that?Zeynab Mousavikhamenehttps://jp.mathworks.com/matlabcentral/profile/authors/14179884-zeynab-mousavikhamenetag:jp.mathworks.com,2005:Question/5592592020-07-04T04:20:35Z2020-07-04T04:20:35ZOBPSK modulation and demodulation in SimulinkHello, I've got a task to make an OBPSK modulator and demodulator in Simulink, and to simulate the signal transmittion with such modulation.
However, I could not find any description on OBPSK modulation. There are no build in example or blocks of OBPSK modulation in Simulink R2016b, and, as I'm afraid, in later versions too.
I've tried to do mine Simulink model which would transmit Barker code, based on my understanding of OBPSK.
However, the constellation diagram I see is kidna wrong (?). I suppose it should be like this
Instead, I'm getting this:
The dot's are moving left and right symmetrically.
Please help, what I'm doing wrong? Is there another way to make OBPSK in Simulink.
Thank you for your responces.Alex Konevhttps://jp.mathworks.com/matlabcentral/profile/authors/18910938-alex-konevtag:jp.mathworks.com,2005:Question/5592562020-07-04T04:07:31Z2020-07-04T04:07:31Zfixed bed adsorption column model-solving PDE-freundlish isothermfunction main
%System Set-up %
%Define Variables
%D = 3*10^-8; % Axial Dispersion coefficient
%v = 1*10^-3; % Superficial velocity
%epsilon = 0.4; % Voidage fraction
%k = 3*10^-5; % Mass Transfer Coefficient
%Kf=2.5*10^-5; %freundlish parameter
%nf= 1.45; %freundlish constant
cFeed = 10; % Feed concentration
L = 1; % Column length
t0 = 0; % Initial Time
%tf = 1000; % Final time
tf = 2000; % Final time
dt = 0.5; % Time step
% z=[0:0.01:L]; %Mesh generation
z = [0:0.0005:L]; %Mesh generation
t = [t0:dt:tf];% Time vector
n = numel(z); % Size of mesh grid
%Initial Conditions / Vector Creation
c0 = zeros(n,1);
c0(1) = cFeed;
q0 = zeros(n,1); % t = 0, q = 0 for all z, this makes sense to me
y0 = [c0 ; q0]; % Appends conditions together
%ODE15S Solver
[T, Y] = ode15s(@(t,y) MyFun(t,y,z,n),t,y0);
%plot(T,Y);
plot(T,Y(:,n)/cFeed)
end
function DyDt=MyFun(~, y, z, n)
% Defining Constants
D = 3*10^-8; % Axial Dispersion coefficient
v = 1*10^-3; % Superficial velocity
epsilon = 0.4; % Voidage fraction
k = 3*10^-5; % Mass Transfer Coefficient
Kf=2.5*10^-5; %freundlish parameter
nf= 1.45; %freundlish constant
% Variables being allocated zero vectors
c = zeros(n,1);
q = zeros(n,1);
DcDt = zeros(n,1);
DqDt = zeros(n,1);
DyDt = zeros(2*n,1);
zhalf = zeros(n-1,1);
DcDz = zeros(n,1);
D2cDz2 = zeros(n,1);
c = y(1:n);
q = y(n+1:2*n);
% Interior mesh points
zhalf(1:n-1)=(z(1:n-1)+z(2:n))/2;
for i=2:n-1
%DcDz(i) = ((z(i)-z(i-1))/(z(i+1)-z(i))*(c(i+1)-c(i))+(z(i+1)-z(i))/(z(i)-z(i-1))*(c(i)-c(i-1)))/(z(i+1)-z(i-1));
DcDz(i) = (c(i)-c(i-1))/(z(i)-z(i-1));
D2cDz2(i) = (zhalf(i)*(c(i+1)-c(i))/(z(i+1)-z(i))-zhalf(i-1)*(c(i)-c(i-1))/(z(i)-z(i-1)))/(zhalf(i)-zhalf(i-1));
end
% Calculate DcDz and D2cDz2 at z=L for boundary condition dc/dz = 0
DcDz(n) = 0;
D2cDz2(n) = -1.0/(z(n)-zhalf(n-1))*(c(n)-c(n-1))/(z(n)-z(n-1));
% Set time derivatives at z=0
% DcDt = 0 since c=cFeed remains constant over time and is already set as initial condition
% Standard setting for q
DqDt(1) = k*(kf*(c(1)^(1/nf))-q(1));
DcDt(1) = 0.0;
% Set time derivatives in remaining points
for i=2:n
%Equation: dq/dt = K(q*-q) where q*=kf*(c^(1/nf))
DqDt(i) = k*(kf*(c(i)^(1/nf))-q(i));
%Equation: dc/dt = D * d2c/dz2 - v*dc/dz - ((1-e)/(e))*dq/dt
DcDt(i) = D*D2cDz2(i) - v*DcDz(i) - ((1-epsilon)/(epsilon))*DqDt(i);
end
% Concatenate vector of time derivatives
DyDt = [DcDt;DqDt];
end
This is the code which I am using. I don't have much knowledge about Matlab but I need to finish the code for my thesis. My question is, I need to model a fixed bed to obtain the breakthrough curves using freundlish isotherm, so, I would like to know how to obtain these curves (C/C0 vs t) from this code. i cant run this code i dont know where is the problem. I would appreciate any help. Thank you very much
nashwa tarekhttps://jp.mathworks.com/matlabcentral/profile/authors/18668615-nashwa-tarektag:jp.mathworks.com,2005:Question/5234122020-05-06T11:31:42Z2020-07-04T04:03:58ZPass Array Variable to MATLAB Function in BashAim
On a Linux High Performance Computing (HPC) system, I am using multiple text files to set variables and array variables in a bash script. These are variables are then the input arguments to a MATLAB function that is run through bash. This MATLAB function runs iteratively creates url download strings (based on the variables mentioned above) and then download corresponding temperature data using MATLAB's websave function. Notably, the MATLAB script uses parfor to parallelise a for loop and spread it over 44 cores on a Linux high performance computing cluster. The MATLAB functions runs fine on the laptop, but extremely slowly, that's why I need to run it from the High Performance Cluster.
Issue
If I open the matlab app via the linux commandline then I can get the function to run. However, I want to send this as a job to a HPC scheduler - meaning I cannot work interactively. Thus, I need to run the function from a bash script.
I am having trouble passing the bash script variables to the matlab function. Note I have tried removing the single quotes from around the variables in the matlab function call, however I get the same error.
Function Example
function f_Download_CRW_Temp(Lat, Long, StartYear, EndYear, SiteNumber, NumCores, FileType)
% <code to set the download url string based on site, latitude, longitude, and start and end dates>
parpool(NumCores) % this will be 44 in the
parfor d = 1:length(Years)
options = weboptions('Timeout',Inf);
url = % <code>
filename = % <code>
try
websave(filename,url,options);
catch
% < Failure report code >
end
end
% < write failure report to text file>
end
Bash Script (not in MATLAB syntax)
cd CRW_Temp_Profiles
# Set Variables
IFS=$'\r\n' GLOBIGNORE='*' command eval 'LatArray=($(cat Lat.txt))'
IFS=$'\r\n' GLOBIGNORE='*' command eval 'LongArray=($(cat Long.txt))'
IFS=$'\r\n' GLOBIGNORE='*' command eval 'SitesArray=($(cat Sites.txt))'
Site=$(echo ${SitesArray[${SLURM_ARRAY_TASK_ID}-1]})
FileType=".csv"
# Check Variables were read properly
echo 'Site is Number '${Site}
echo 'Row-specific LatLons are:'
echo ' deg N = '${LatArray[${SLURM_ARRAY_TASK_ID}-1]}
echo ' deg S = '${LongArray[${SLURM_ARRAY_TASK_ID}-1]}
echo ' All Lats are'
echo ${LatArray[*]}
# run MATLAB function
module load MATLAB
matlab -nodisplay -nojvm -nodesktop -nosplash -r "try; f_Download_CRW_Temp('$LatArray', '$LongArray', "1985", "2019", '$Site', "44", ".csv"); end; quit;"
module purge
Bash Output and Error Message
Site is Number 1
Row-specific LatLons are:
deg N = -16.5
deg S = 149.8
All Lats are
-16.5 -20 -19.5 -11.5 -23.5 -21.5 -31.5 ..... <100 entries of site latitudes> .... 11.2 11.2
< M A T L A B (R) >
Copyright 1984-2018 The MathWorks, Inc.
R2018b (9.5.0.944444) 64-bit (glnxa64)
August 28, 2018
For online documentation, see https://www.mathworks.com/support
For product information, visit www.mathworks.com.
try; f_Download_CRW_Temp('-16.5', '149.8', 1985, 2019, '1', 44, .csv); end; quit;
Error: Invalid use of operator.Liam Lachshttps://jp.mathworks.com/matlabcentral/profile/authors/17825726-liam-lachstag:jp.mathworks.com,2005:Question/5287782020-05-21T06:53:44Z2020-07-04T03:53:49ZCan I name data in the scatter graph?I need a name of data on the graph.
The data & graph are attached below.
I want to draw it like an attached image file.
I need a professional's help.
Thank you. Have a nice day!
Changho LEEhttps://jp.mathworks.com/matlabcentral/profile/authors/14352750-changho-leetag:jp.mathworks.com,2005:Question/5586052020-07-02T18:06:05Z2020-07-04T03:31:30ZBi directional buck boost converter with simulink and simscape onlyHello All,
I did design a bi directional circuit in simscape.I used PWM from specialised power system for producing PWM of variable duty cycle.But i see the simulation runs very slowly.When i try increasing the sample time,the circuit functioanlity disappears. How can I increase the speed of my circuit.Kindly help
I'm using ode15s/dasesimscape solver under variable step configurationSushma nhttps://jp.mathworks.com/matlabcentral/profile/authors/12689439-sushma-ntag:jp.mathworks.com,2005:Question/3857562018-03-01T17:33:01Z2020-07-04T03:22:59ZAdsorption Modelling - Solving PDE - Axial Dispersion ModelDear all,
I am trying to develop a simple model for an adsorption column. I have attached a file that contains the equations that I am trying to solve.
To solve the system, I am trying to solve the axial dispersion model (neglecting pressure drop, and hence, the dv/dz term) alongside the Linear Driving Force (LDF) model, which gives an expression for dq/dt in the axial dispersion PDE (see attached file). I am also using the Langmuir equation to give an expression for q* (equilibrium concentration) in the LDF equation.
Unknown variables are q and c, all other variables are known (i.e. D, v, epsilon etc.( / are the independent variables (i.e. time, t, and length, z).
I have tried using the Method of Lines to solve this system (again, see attached file), but I am aware that the system I have developed is flawed.
Any suggestions on how to approach this problem would be appreciated. I would preferably like to solve the system using either a PDE solver or ode45 applied to the method of lines.
My code so far is as follows:
Data File:
%% Constants
D = 3*10^-8; % Axial Dispersion coefficient
v = 1*10^-3; % Superficial velocity
epsilon = 0.4; % Voidage fraction
k = 3*10^-5; % Mass Transfer Coefficient
bH = 2.5*10^-5; % Langmuir parameter for H2
L = 1; % Column length
%% MoL Coefficients & Mesh Generation
N = 20;
dz = L/N;
z = [0:dz:L];
% MoL Coefficients from Discretisation
alph = ((D/(dz^2)) + ((v)/(2*dz)));
bet = ((-2*D)/(dz^2));
gamm = ((D/(dz^2)) - ((v)/(2*dz)));
%% Initial / Boundary Conditions
% Initial condition for ODE 1:
c0 = 0; % C at t = 0 for all z
% Boundary Condition for ODE 1:
cFeed = 10; % C at z = 0 for all t
qs = (1+bH*cFeed)/(bH*cFeed); % Conc. of adsorbed phase at surface saturation
% Initial Condition for ODE 2:
q0 = qs*((bH*cFeed)/(1+bH*cFeed))-1; % Initial concentration in adsorbed phase
% Time Boundaries
t0 = 0;
tf = 10000;
% Initial equilibrium conc.
qeq0 = qs*((bH*c0)/(1+bH*c0));
dq0 = k*qeq0;
Solving using ODE45:
close all
clear all
clc
% Call Data File
DataFile;
tspan = [0:10000];
[t,c] = ode45('cprime', tspan, c0);
Cprime file
function [ dcdt ] = cprime(~, c)
% Call data file to define constants
DataFile;
t=t0;
q = q0;
[dqdt] = qprime(t, q, k, qs, bH, c);
%% Create Tri-diagonal Matrix A
A = zeros(N,N);
for i = 2 : N-1
A(i, i-1) = alph;
A(i, i) = bet;
A(i, i+1) = gamm;
end
A(1,1) = bet;
A(1,2) = gamm;
A(N,N-1) = alph+gamm;
A(N-1, N) = gamm;
A(N,N) = bet;
b = ones(N,1);
b(1) = cFeed*alph-((1-epsilon)/(epsilon)*(k*(qeq-q)));
dcdt = (A*c + b);
end
qprime file:
function [dqdt] = qprime(~, q, k, qs, bH, c)
DataFile;
qeq = qs*((bH*c)/(1+bH*c));
dqdt = k*(qeq-q);
end
I am really struggling to figure out how to structure my code / approach these equations.
Any help would be muchly appreciated!
Thanks!
Ashley Grattonhttps://jp.mathworks.com/matlabcentral/profile/authors/8938463-ashley-grattontag:jp.mathworks.com,2005:Question/2472812015-10-07T13:16:18Z2020-07-04T03:18:19Zwant ideas for contour, z is not a function for x,yI'm begginer this.
I want draw a gragh using "contour".
I know the way of this is contour(x,y,Z) at help.
here, Z is function for x,y.
is it only this rule?
I want use this with Z is constant.
for example,
x y z
1 .2 10
2 .3 11
3 .4 12
4 .5 13
5 .6 14
as you can see, Z is not a function for x,y, constant.
Can I draw that using contour(or contourc, contourf... series of contour)?
How to ~ plz~Byungsoo Yoohttps://jp.mathworks.com/matlabcentral/profile/authors/7069287-byungsoo-yootag:jp.mathworks.com,2005:Question/5592112020-07-03T23:32:32Z2020-07-04T03:15:59ZConvert several columns char matrix into one column char matrixI have a 200x12 matrix, with hours, minutes, seconds info. Each row has a time format like this: "13:35:43,050", but each column is composed of a single character of the time format ("1" in column 1; "3" in column 2; ":" in column 3, etc).
I would like to end up with a 200x1 matrix, where all the column characters would appear in a single column, with no spaces.
Can you help me, please? Thank you very much.Cláudia Oliveirahttps://jp.mathworks.com/matlabcentral/profile/authors/18910182-claudia-oliveiratag:jp.mathworks.com,2005:Question/559142012-12-06T15:29:39Z2020-07-04T03:15:15ZWhat are the MATLAB job options?Hi,
It seems to me that most of the companies that hire programmers are looking for C++, Python, Java, etc. skills but very rarely I saw in a job post any requirements about MATLAB. Do you know any company which hires people for MATLAB programming (+ research)? This was extremely useful for me in my research as a grad. student (because I could spend most of my time thinking about the problem than writing code) so I guess there have to be also firms that realized the advantages of MATLAB...Razvanhttps://jp.mathworks.com/matlabcentral/profile/authors/1817115-razvantag:jp.mathworks.com,2005:Question/5584722020-07-02T14:11:51Z2020-07-04T02:52:32Zfgetlで空行を認識したいfgetlで空行を認識したい。
以下のPRGでは、q2.txtをfgetlで読見込みをおこないます。
下記のようにすれば可能ですが、%行でもできると思うのですが、空行を認識しません。
アドバイスをいただけませんか？
%e81.m
fileID = fopen('q2.txt'); % q2' = [1 2 3
while(1)
tline = fgetl(fileID)
if length(tline)==0 fprintf(" blank line\n");
%if tline==[] fprintf(" blank line\n"); % unrecognized, why?
elseif tline<0 fprintf(" file end\n"); break; end
end
fclose(fileID);
%{
%q2.txt
1
2
3
4
5
%}fumio hakamadahttps://jp.mathworks.com/matlabcentral/profile/authors/9899576-fumio-hakamadatag:jp.mathworks.com,2005:Question/4333912018-12-02T21:31:33Z2020-07-04T02:46:47ZThe number of worker in parallel computation in cluster slurmIn my matlab code i'm using parfor to do simulation , i set up the number of workers to be 12 as :
parpool('local',12);
Then the associated batch scipt to send as job to cluster is :
#!/bin/bash
#SBATCH --job-name=job1
#SBATCH --output=output.out
#SBATCH -t 90-00:00:00
#SBATCH --nodes=1
#SBATCH --ntasks=12
#SBATCH --mem-per-cpu=3000M
module load matlab/2015b
matlab -nosplash -nodesktop -r "mycode; exit"
The first problem is that i didnt find any faste implementation when i set up the number of worker s to 16 insted of 12
The second problem is that when i set up number of workers to 32 , i got this error after sending the job .
error msg : Batch job submission failed: Requested node configuration is not available
Can any one help me , i might have to include more information in batch script , i put ntasks per node =12 which is the same as the number of workers in matlab code .
Dalal Salemhttps://jp.mathworks.com/matlabcentral/profile/authors/10429973-dalal-salemtag:jp.mathworks.com,2005:Question/5592502020-07-04T02:16:40Z2020-07-04T02:44:33ZNot got the ordered student suite license I'd purchased a student suite license yesterday,now when I tap on the orders it is showing "your order is still processing ". Please provide any Help .Thank you in advance.Nirmal Kumar Barickhttps://jp.mathworks.com/matlabcentral/profile/authors/18907219-nirmal-kumar-baricktag:jp.mathworks.com,2005:Question/5587762020-07-03T03:32:30Z2020-07-04T02:44:30ZConvert Fortran code to MatlabHi, I need help in converting the following Fortran code to Matlab
* This program reads binary data for 365/366 days and writes in ascii file.
PROGRAM READ
PARAMETER(ISIZ=31,JSIZ=31)
DIMENSION T(366,ISIZ,JSIZ)
OPEN(1,FILE='D:\\DailyT\\MeanT\\MEANT1980.GRD',
1 FORM='UNFORMATTED',ACCESS='DIRECT',
2 RECL=ISIZ*JSIZ*4,STATUS='OLD')
OPEN(2,FILE='D:\\DAILYT\\MEANT15APR1980.TXT',STATUS='UNKNOWN')
* TAKE NDAY=366 FOR LEAP YEARS
NDAY=366
DO IDAY = 1,NDAY
READ(1,REC=IDAY)((T(IDAY,I,J),J=1,JSIZ),I=1,ISIZ)
ENDDO
WRITE(2,'('' Daily Tempereture for 15 APR 1980 '')')
DO I = 1,ISIZ
WRITE(2,'(31F6.2)')(T(106,I,J),J=1,JSIZ)
ENDDO
STOP
END
Thanks
ShubhamKalore Shubham Arunhttps://jp.mathworks.com/matlabcentral/profile/authors/13904198-kalore-shubham-aruntag:jp.mathworks.com,2005:Question/5571492020-06-30T09:50:32Z2020-07-04T02:40:31ZHow to install pardiso on matlab with `pthread` on windows?I am trying to use PARDISO in Matlab on windows. I notice that some compile options may not availible for windows system. This is my building script for pardisofree.mexw64 as an example.
mex -largeArrayDims -lpardiso -lmwlapack -lmwblas ...
-LD:\IntelSWTools\parallel_studio_xe_2019.0.045\compilers_and_libraries_2019\windows\compiler\lib\intel64_win -lifcoremt ...
-LD:\zw\matlab\PARDISO\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64 -lpthread ...
-lm -output pardisofree ...
common.cpp matlabmatrix.cpp sparsematrix.cpp pardisoinfo.cpp pardisofree.cpp
I have installed the intel parallel XE to get the windows version of gfortran, as lifcoremt.lib.
I also download pthread for windows version from sourceforge https://sourceforge.net/projects/pthreads4w/
So the command above runs ok for me. But I still have any way to activate the multithreads. I got no examples for that. How to build a matlab file to check it? Do I need to compile OPENMP into it? Any suggestion would be appreciated. I am really confused in this process.
wei zhanghttps://jp.mathworks.com/matlabcentral/profile/authors/3994770-wei-zhangtag:jp.mathworks.com,2005:Question/4974012019-12-19T11:17:51Z2020-07-04T02:20:32ZPARDISO, reuse symbolic factorizationI installed the matlab package from pardiso-project.org, and I built the .mex linking with libpardiso600-WIN-X86-64.lib.
I'm solving in a loop a series of problems Ax=b, where A changes, but still has the same sparsity pattern. To exploit that, in the initialization, I only perform symbolic factoriazation once (which supposes to allocate the data structures), and I free it only once; this is the general idea:
pardiso_info = []
bSolverInitialized = 0;
for i = 1:n
A = As{i};
rhs = rhses{i};
A = A + eps*speye(size(KKT)); % diagonal must be full
A = tril(KKT);
% initialize
if bSolverInitialized
bSolverInitialized = 1;
pardiso_info = pardisoinit(-2,0);
% Analyze the matrix and compute a symbolic factorization.
pardiso_info = pardisoreorder(A, pardiso_info, false);
end
% Compute the numeric factorization
pardiso_info = pardisofactor(A, pardiso_info, false);
% Compute the solutions using the symbolic factorization
[sol, obj.pardiso_info] = pardisosolve(A, rhs, pardiso_info, false);
end
pardisofree(pardiso_info);
clear pardiso_info;
I execute this code many times (in an outer loop). Matlab memory usage increases until it hangs. I suspect a memory leak, and pardiso is my prime suspect. I'll need to do further testing to try and pinpoint the problem, but I thought to verify first that I'm using it correctly since the manual didn't mention reusing symbolic factorization.
I'm not sure if it's the right place for the question. pardiso-project.org doesn't seem to have a forum, but Intel may support it as part of MKL.Zoharhttps://jp.mathworks.com/matlabcentral/profile/authors/2906003-zohar