Find the error in the code

Assignment Help Data Structure & Algorithms
Reference no: EM13943850

function out=bisect_1(fname, a, b, eps)
% bisection algorithm
% fname must be a function handle (if you want to use a string instead,
% use eval)
% sign(fa)*sign(fb) must be negative where fa=feval(fname,a) and
% fb=feval(fname,b)
%
% Example:
% fname=@(x)(exp(-cos(x))-1);
% root1=bisect_1(fname, 1, 2, 1e-3);
% root1
%
% To find the second root, use a=4 and b=5
% To find the third root, use a=7 and b=8
%
% Now to compare the results, use fzero() function
% first root-->fzero(fname, 1)
% second root-->fzero(fname, 5)
% third root-->fzero(fname, 8)
%
% You could add more codes to check the inputs to the function
% and act accordingly.
%
out='root not found';
if sign(feval(fname,a))*sign(feval(fname,b)) > 0
disp('function doesn''t cross zero betwenn the specified interval!!');
return ;
end
N=100; %to avoid infinite loop
found=false;
iter=0;
while(iter<N)
iter=iter+1;
c=(a+b)/2;
fa=feval(fname,a);
fb=feval(fname,b);
fc=feval(fname,c);
if (fc==0 || (b-a)/2<eps)
out=c;
found=true;
break;
else
if sign(fc)==sign(fa)
a=c;
else
b=c;
end
end
end
if found==false
disp('Root not found!')
end

The error Iam getting for the above code
??? Input argument "fname" is undefined.

Error in ==> bisect_1 at 25
if sign(feval(fname,a))*sign(feval(fname,b)) > 0

function out=insertionSort(inArray)
% insertion sort algorithm
% inArray must be a vector
% out is the result of insertion sort
% Example:
% a=round(10*rand(1,10)+1);
% a_sorted=insertionSort(a);
% a_sorted
%

for i=1:length(inArray)
temp=inArray(i);
j=i;
while (j>1 && inArray(j-1)>temp)
inArray(j)=inArray(j-1);
j=j-1;
end
inArray(j)=temp;
end
out=inArray;

??? Input argument "inArray" is undefined.

Error in ==> insertionSort at 11
for i=1:length(inArray)

function out=my_cos(x, N, varargin)

%check for eps
if length(varargin)>1
disp('number of arguments must be 2 or 3!!')
return;
elseif length(varargin)==1
eps=varargin{1};
else
eps=0;
end

%start estimation
result=0;
for i=0:N-1
%calculate i-th term
numerator=(-1)^i;
denom=factorial(2*i);
factor=x^(2*i);
temp=(numerator/denom)*factor;
%compare to eps
if abs(temp)>eps
result=result+temp;
else
break;
end
end
out=result;

error for the above code
??? Input argument "N" is undefined.

Error in ==> my_cos at 15
for i=0:N-1

Reference no: EM13943850

Questions Cloud

Expected value for this decision scenario : What is Expected value for this decision scenario, given that Pr(good) = 0.7? Assume you will face this decision scenario yearly for many years.
Why is the study the humanities important : How can interaction with other cultures or societies influence and benefit a culture? How are art and culture reflective of the changing concepts of nature, society, and the individual?
What common source of cash inflows from investing activities : What are the most common sources of cash inflows from financing and investing activities? What are the most common cash outflows related to investing and financing activities?
Evaluate four websites for comprehensive analysis : Required to evaluate four (4) websites for which a comprehensive analysis must be performed. These websites include: • There will be two websites that represent a large organisations and a government agency.
Find the error in the code : The error Iam getting for the above code
Comment on whether each of the following three industries : Comment on whether each of the following three industries is sensitive to the business cycle. If it is sensitive, does it do better in a boom period or a recession?a) Auto-mobilesb) Pharmaceuticalsc) Housing
Minimising the foreign political risks : Explain the measures that are available to a company to minimise its foreign political risks.
Standard rankine cycle problem using steam : This is a refrigeration cycle problem using propane (use p-H chart for propane in Appendix). 5.15 This problem is a Claude liquefaction process for methane. (Use methane p-H chart in Appendix). 6.2 (a, c, f, h, i) Here you are asked to express var..
Relationship with the community : Task Mr Jack testified of his blood sugar level being under control, his relationship with the community is civil. He complied with his medication and his spiritual needs are met. How would you analyse the care given to Mr Jack in terms of the hol..

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  How the two versions of the algorithm compare

A brief introduction of the sorting algorithm that you have selected and how the two versions of the algorithm compare.

  Prove that you should not also use the greedy strategy

Prove that you should not also use the greedy strategy. That is, show that thereis a game that you can win, but only if you do not follow the same greedy strategy as Elmo.

  Content of the queue at the beginning

Assume you are at the airport, waiting for the security check. There is one line (which is a FIFO queue), and 5 security check gates. Each person reaching in front of the queue is checked by the first available security gate.

  Research paper - cognitive modeling and human interaction

The paper can be a review that covers current solutions on Cognitive modeling and human interaction, or a research paper that proposes your own opinions/solutions.

  Find terminal nodes in tree nil if pointer is represented

The node's right child. If the nil pointer is represented by 00 and the tree's root pointer contains 53, how many terminal nodes are in tree?

  Write an algorithm that displays the squares of the number

Using a FOR loop,I need to write an algorithm that displays the squares of the number 1 to 10to console out put

  Illustrate how b-tree will expand

Illustrate how tree will expand (after inserting each Part#), and what the final tree would like. (b) Repeat item (a), but use a B-tree of order p = 4 instead of a B+-tree.

  What is the most favorite loop structure, and why

Give an example of how you might use a C array to solve a real life business problem.

  C++ program to evaluate expressions combining set union

Create a C++ program to evaluate expressions combining set union, set intersection and parentheses

  Determine schedule that obtains maximum amount of profit

Assume you have one machine and a set of n jobs a1, a2, ..., an to process on that machine. Determine the schedule that obtains the maximum amount of profit. Compute the running time of your algorithm?

  Write algorithm which divides n objects of u into k clusters

Suggest the algorithm which divides n objects of U into k clusters, making use of MST of a graph. Give a simple argument of correctness and bound on the running time of the algorithm you are proposing.

  Complete proof that the graph bgais indeed a buffer graph

Complete the proof that the graph BGa (defined in the proof of Theorem 5. 13) is indeed a buffer graph, i. e., for each path P E P there exists a guaranteed path with image P.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd