Calculating Sequence of Square Roots with MATLAB Function and Script

In summary, the conversation discussed creating a MATLAB function to calculate the sum of square roots of values in a given vector. It also mentioned writing a script to test the function by generating a random vector and using the function repeatedly to calculate a sequence. The calculated values were then saved to a vector and displayed and plotted.
  • #1
jmed
46
0

Homework Statement


Implement a MATLAB function y=radicals(v) that calculates sqrt v(1) + sqrt v(2) +sqrt v(3) +...sqrt v(n). These values are components of v.
Then I need to write a script to test function. Enter positive integer k. Generate random vector r of length k using rand function. Then calculate following sequence by calling function radicals repeatedly. sqrt r(1), sqrt r(1)+sqrt r(2), sqrt r(1)+sqrtr(2)+sqrt r(3),...
, sqrt r(1)+sqrt r(2)+sqrt r(3)...+sqrt r(k)

Save calculated values to a vector seq. Display and plot seq.


Homework Equations





The Attempt at a Solution



Set up a function y = radicals(v)

function y=radicals(v)
n = 1
?
 
Physics news on Phys.org
  • #2
sqrt_v = sqrt(v(n));for n = 2:length(v)?sqrt_v = sqrt_v + sqrt(v(n)); endy=sqrt_v;endWrite a script to test functionk = input('Enter a positive integer k: ')r = rand(1,k);seq = zeros(1,k);for n = 1:kseq(n)= radicals(r(1:n));enddisp(seq);plot(seq);
 

Related to Calculating Sequence of Square Roots with MATLAB Function and Script

1. What is a Matlab function?

A Matlab function is a block of code that performs a specific task or set of tasks. It can take in inputs, process them, and produce outputs. Functions are useful for organizing and reusing code in a modular way.

2. How do I access the help documentation for Matlab functions?

To access the help documentation for Matlab functions, you can use the "help" command followed by the name of the function. Alternatively, you can use the "doc" command to open up the documentation in a separate window.

3. What information is included in the Matlab function help?

The Matlab function help typically includes a brief description of the function, its syntax, input and output arguments, and examples of how to use the function. It may also include related functions and links to more detailed documentation.

4. How can I find specific information within the Matlab function help?

You can use the search function within the Matlab help documentation to find specific information related to the function you are interested in. You can also use the "Contents" tab to navigate to different sections of the documentation.

5. Can I contribute to the Matlab function help documentation?

Yes, you can contribute to the Matlab function help documentation by submitting feedback or suggestions directly to MathWorks, the company behind Matlab. You can also participate in the community forums to share your knowledge and help others with their questions.

Similar threads

  • Calculus and Beyond Homework Help
Replies
27
Views
914
  • Calculus and Beyond Homework Help
Replies
10
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
688
  • Calculus and Beyond Homework Help
Replies
8
Views
989
  • Calculus and Beyond Homework Help
Replies
4
Views
576
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
980
  • Calculus and Beyond Homework Help
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
569
  • Calculus and Beyond Homework Help
Replies
2
Views
764
Back
Top