How do I integrate a vector in MATLAB [closed] - matlab

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to perform integration on a vector L but I don't know exactly what to use. I want to obtain a (the integral) as a vector that is the same size as NT.
clc;clear;
syms x
NT=input('NT=');
L=zeros(NT,1);
for i=1:NT
disp('Longeur de travée')
L(i)=input('L = ');
L(i)=L(i);
fa(i)=L(i).*x^2;
a(i)=int(fa)
end

An easy way would be to use trapz. If you have X and Y such that Y(i) = f(X(i)) (so Y contains the values of some function at the location X) then you simply do
I = trapz(X, Y)
In your case, you can do
I = trapz(L, fa)
I guess, looking at your code.
Note that you could use more advanced techniques, that will, in principle, give you a better result (because they are higher-order). This is just one method, but an easy one.

Related

Sum Matlab from 0 to 10000 on function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
syms k
S1 = symsum(1/((2*k)+1)^2,k,0,1000)
The result is this
59039372973827482202940226722672826425297321906316082356858983822169051832268260251807527611479190413293513875429587706186073872918905490907386679472102966658686481651660967093301512141946288248492833396616338323741632085379508599235923841007033467883638349122388806376761808189104503262045883240287482992169819848342303098664924237976221795758421152603069387903705445513260596627332283139648508194960733619500093010571517561429904500013876585156927070119332440687162376758374919870699278800835146651318465663183182583101377584105366558079836223068786457324044080570317649838092783113721959819118571747662368360095513856052974454509201490370810246175872510881504730747209788019551000695511879992198550955686739483474761130248789609061549535677663474218135370195381615899214931316241080337028498241295985409686314819267606796712968280842464845294917738460317179001491697993067157425958639996885239616893392960282441289069600101430806922004624472226999315951355963789249300352610312601262349650287009275097201871774652260892220551489305368617001974326978428202443548923140478853569492070442010110016068635424791389124439271253578545895132216218268847919848655110002938693346760862649668457282775860633067627110099340660770861888592018701206483696615682617062811616008107086256694453990688805738127607846586853460003073465075155412119309273843527076321601670400373937698518621100907936577387919537592519265365346619712200304996044229704602647674114176291753575322917531444831938509001759491229575945273985556769609288625450013634760596805884195325794441020339210402987018058377081579351119704065092777310976461961832919116412535470810011337916688085616171422473409544885864650134157327448050685723673514545806331081542320899927
It is a number in this form a/b
Why is this happening??
Do you know how to do this in octave too?
k = (0:1000);
k_sum = sum(1./((2*k)+1).^2);
disp(k_sum)
It's interesting that you jumped straight to using syms when the basic matlab functions work perfectly well for this problem. Why is that?

How can I use Non-linear Fitting function on Matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have Non-linear Fitting function like:
prate ~ (m1-((m1-m2)/(1+(IC50/(conc)))))
And a table:
[I] (µM) Max polymerization rate
25.00 3.08
12.50 3.30
6.13 4.44
and IC50 = 1.87
I want to create a function like the one above and use this data to make a plot. Is that possible?
This might help you get started.
You need to define your function using handles.
Say you have a variable PolymerRate you want to estimate and conc as input variable, I think in your case would be something like:
IC50 = 1.87;
prate = #(m,conc) (m(1)-((m(1)-m(2))/(1+(IC50/(conc)))));
m0 = [1 1];
[m,resnorm,~,exitflag,output] = lsqcurvefit(F,m0,conc,PolymerRate);
plot(conc,PolymerRate,'ro')
hold on
plot(conc,prate(m,conc))

Save cell arrays in one CSV - Matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a script which generates a 2 cell array (x and y coordinates). How can I merge them (two columns), save them in one CSV file so I can read them later in Excel?
Below some simplified code which has two solutions that might help you
x = 1:10;
y = 11:20;
x = num2cell(x);
y = num2cell(y);
x2 = cell2mat(x);
y2 = cell2mat(y);
newmat = [x2;y2]';
csvwrite('output.csv',newmat)
fid = fopen ('output2.csv','w');
for i = 1:length(x)
fprintf (fid,'%f, %f\n',x{i},y{i});
end
fclose (fid);
related to what GameOfThrows mentions this only works if x and y have the same length
Note the first solutions converts the cell to an arra which might not always give the result as shown in the example. The second is a more general one with a formatted output...

How can I write this using Matlab with for loop, ones, and zeros? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Please help me out with this code:
for i = 1:n
u(t - a_i - td_i);
end
where:
u: step function
t: time vector with n elements
a_i, tau_i, and td_i: variables that change inside for loop
I guess I need to use zeros and ones, but how can I do this correctly?
Simple function to sum the value inside the loop:
func = #(t) sum(t > a + td)
func(t) will be the sum of the foor loop

How to separate objects by colour matlab [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want the Matlab to recognize colors and analyse the object if it yellow otherwise it would ignore it.
I know how to analyze the objects but I don't know how to eliminate the other non-yellow ones
The most simple approach that I can come up with is this quick and dirty program:
i = imread('school_zone.jpg');
r = i(:,:,1);
g = i(:,:,2);
b = i(:,:,3);
threshold = 100;
isyellow = r > threshold & g > threshold & b < threshold;
(b < threshold to prevent the white to be confused with yellow)
imshow(isyellow);