Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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 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 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

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91614715
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Stack - java plz use simple java language netbeans 81 or

STACK - java, plz use simple java language, netbeans 8.1 or 8.2 1. Create a Stack class based on MyLinkedList class. Use this class in the following: 2. Create a new Java Application that has the following methods: 1. A ...

A farm has two types of trees 30 are orange trees o and 70

A farm has two types of trees: 30% are orange trees (O) and 70% are apple trees (A). Frost (F) has damaged 40% of the orange trees (F|O)=0.4 and 10% of apple trees. What is the probability that a randomly selected tree w ...

Sectuon 112 build draw binary search tree with the names

Sectuon 11.2: Build draw binary search tree with the names Doc, Grumpy, Happy, Sleepy, a Bashful, Sneezy, Dopey, inserted in the order provided here. Assume that, on future searche of this tree, each name is equally like ...

Question provide a real-world example or describe a

Question: Provide a real-world example or describe a hypothetical situation in which a legitimate organization used spam in an effective and nonintrusive manner to promote a product or service. Need 300-350 words APA sta ...

Please help with anbspfunctionnbspcodesymbol to convert

Please help with a function  codeSymbol , to convert each mark to a symbol (A, B, C, D, E, F) and a code (7,6,5,4,3,2,1) according to the table below. And call it in the main function. Use the table below to determine th ...

Subject computer algorithmsbook introduction to algorithms

Subject : Computer Algorithms Book: Introduction to Algorithms 3rd edition 1) a) Using Figure 10.1 as a model, illustrate the result of each operation in the sequence PUSH(S,6), PUSH(S,2), PUSH(S,8), POP(S), PUSH(S,5), P ...

A researcher thinks that listening to classical music

A researcher thinks that listening to classical music reduces anxiety. She measures the anxiety of 10 persons then plays Mozart's "Eine Kleine Nachtmusik". Following that the researcher measures their anxiety again. (Not ...

A group of adult males has foot lengths with a mean of 2693

A group of adult males has foot lengths with a mean of 26.93 cm and a standard deviation of 1.12 cm. Use the range rule of thumb to identify the limits separating values that are significantly low or significantly high. ...

Select a failed software project and run a postmortem

Select a failed software project and run a postmortem analysis on it. You may choose one discussed in class or research one yourself. In your analysis, identify the following: What was the purpose of the software? How di ...

What does the super keyword represents and where can it be

What does the super keyword represents and where can it be used? Give an example of a superclass and subclass. Be sure to make all the instances variables of the super class private. Include at least one constructor in e ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As