Question

clc,clear N =input('Enter positive number\n'); d=0; x = i; for i= 2:N-1 if (mod(N,i)==0) for j=...

clc,clear
N =input('Enter positive number\n');
d=0;
x = i;
for i= 2:N-1
if (mod(N,i)==0)
for j= i:N
if (mod(i,j)==0)
d = d+1;
fprintf('%d\t \n',i);
end
  
end
end

How can I determine the Positive PRIME factors only out of this code? What should I debug? (MATLAB)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Execute demo.m STDIN 1 clc,clear 2 N input( Enter positive number\n); 3 for i-2:N 4 if (mod(N,1)--0) 6 7 for j-2:i/2 if (mod (i,j)--e) break 10 end 12 13 end if (d-1) fprintf(dtn,i); end 15 16 end end

Output

input: 15

Add a comment
Know the answer?
Add Answer to:
clc,clear N =input('Enter positive number\n'); d=0; x = i; for i= 2:N-1 if (mod(N,i)==0) for j=...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5.i) What will be the output of the script: for i-1:7 for j- 1:i fprintf(%d", j)...

    5.i) What will be the output of the script: for i-1:7 for j- 1:i fprintf(%d", j) end fprintf('\n') % start a new line. end 5 (i) For ax2 + bxc 0, the value of x is given by 2a Write a MATLAB function quadrasol () that will have three inputs ( a,b, and c) and two outputs corresponding to the solutions of the equation. It may be more compact if you defined another variable 'd' for the term inside the...

  • Translate this matlab code to python title('Starting Number vs Number of Elements in Seq') ylabel('Number of...

    Translate this matlab code to python title('Starting Number vs Number of Elements in Seq') ylabel('Number of Elements in the sequence in the sequence') xlabel('Starting Number') steps = []; vec = 1:25; for i=1:length(vec) s = []; num = i; while true s(length(s)+1) = num; if num == 1 break; elseif mod(num, 2) == 0 num = num/2; else num = (3*num)+1; end end fprintf('%d = ', i) disp(s) fprintf('\n') steps(i) = length(s); end plot(vec, steps)

  • Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument,...

    Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc. NOTE: A prime number is a...

  • I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear...

    I have all of the answers to this can someone just actually explain this matlab code and the results to me so i can get a better understanding? b) (c) and (d) %% Matlab code %% clc; close all; clear all; format long; f=@(t,y)y*(1-y); y(1)=0.01; %%%% Exact solution [t1 y1]=ode45(f,[0 9],y(1)); figure; plot(t1,y1,'*'); hold on % Eular therom M=[32 64 128]; T=9; fprintf(' M Max error \n' ); for n=1:length(M) k=T/M(n); t=0:k:T; for h=1:length(t)-1 y(h+1)=y(h)+k*f(t(h),y(h)); end plot(t,y); hold on %%%...

  • 8 0/1 point How could the following code be re-written with a while loop? % find...

    8 0/1 point How could the following code be re-written with a while loop? % find the index of the first value in A divisible by 3 index = 0; for i = length(A):-1:1 if mod(A(i),3) == 0 index = 1; end end if index > 0 fprintf('The index of the first number divisible by 3 is %d\n', index); end O i=1; while i < length(A) if mod(A(1),3) == 0 index = 1; end SP ^00 201 Tprint("The index of...

  • The first two parts should be solved by Matlab. This is from an intro to Numerical...

    The first two parts should be solved by Matlab. This is from an intro to Numerical Analysis Class and I have provided the Alog 3.2 in below. Please write the whole codes for me. Alog3.2 % NEWTONS INTERPOLATORY DIVIDED-DIFFERENCE FORMULA ALGORITHM 3.2 % To obtain the divided-difference coefficients of the % interpolatory polynomial P on the (n+1) distinct numbers x(0), % x(1), ..., x(n) for the function f: % INPUT: numbers x(0), x(1), ..., x(n); values f(x(0)), f(x(1)), % ...,...

  • Please, I am evaluating an error term y = 5^(n+1)*(n+1) and wish to find the number...

    Please, I am evaluating an error term y = 5^(n+1)*(n+1) and wish to find the number of terms n required for ln (1.2) to yield an error < 10^-5. The manual computation gave me n > 5. But I need to come out with a MATLAB code with explanations and an output to confirm my manual answer. function error a = 1.2 - 1; n = 1; while (1/(n+1) * a^(n+l)) > 10e-6 n = n+1; end fprintf ('n =...

  • CONVERT THE FOLLOWING MATLAB CODE FROM SOURCE PANEL METHOD TO VORTEX PANEL METHOD: clc;clear all;...

    CONVERT THE FOLLOWING MATLAB CODE FROM SOURCE PANEL METHOD TO VORTEX PANEL METHOD: clc;clear all;close all; Vinf=100; % freestream velocity R=1; % cylinder radius n=4; % number of panels alpha=2; % angle of attack dtheta=2*pi/n; theta=pi+pi/n:-dtheta:-pi+pi/n; X=R*cos(theta); Y=R*sin(theta); for i=1:n % angle of flow with tangent of panel phi(i)=-alpha+atan2((Y(i+1)-Y(i)),(X(i+1)-X(i))); % angle of flow with normal of panel beta(i)=phi(i)+pi/2; x_mid(i)=(X(i+1)+X(i))/2; y_mid(i)=(Y(i+1)+Y(i))/2; S(i)=sqrt((Y(i+1)-Y(i))^2+(X(i+1)-X(i))^2); end % Source Panel Method for j=1:n neighbors(:,j)=[1:j-1 j+1:n]; xi=x_mid(j); yi=y_mid(j); for i=1:n-1 m=neighbors(i,j); Xj=X(m); Yj=Y(m); Xj1=X(m+1); Yj1=Y(m+1); A=-(xi-Xj)*cos(phi(m))-(yi-Yj)*sin(phi(m));...

  • 4. The following algorithm step 1: 20 := r; j :=0 step 2: while x; #...

    4. The following algorithm step 1: 20 := r; j :=0 step 2: while x; # 0, do d; := remainder of integer divide x;/2 Xj+1 := quotient of integer divide x;/2 j:= + 1 end while can be used to convert a positive decimal integer x to its binary equivalent, x = (anan-1.0190)2. Implement the algorithm (write a computer program) and apply it to convert the following integers to their binary equivalents. (a) 56 (b) 1543 (The Matlab library...

  • Programming C....... function code is clear but compile is wrong .. I input 8 and compiled...

    Programming C....... function code is clear but compile is wrong .. I input 8 and compiled 2 0 1 1 2 3 5 8 13.. look first number 2 is wrong. The correct answer 8 is 0 1 1 2 3 5 8 13 21.. Need fix code to compile correctly.. Here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[1000]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for (...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT