Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1006077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:24:04+00:00 2026-05-16T08:24:04+00:00

load X_Q2.data load T_Q2.data x = X_Q2(:,1); y = X_Q2(:,2); learningrate = 0.2; max_iteration

  • 0
load X_Q2.data
load T_Q2.data
x = X_Q2(:,1);
y = X_Q2(:,2);

learningrate = 0.2;
max_iteration = 50;

% initialize parameters
count = length(x);
weights = rand(1,3); % creates a 1-by-3 array with random weights
globalerror = 0;
iter = 0;
while globalerror ~= 0 && iter <= max_iteration
  iter = iter + 1;
  globalerror = 0;
  for p = 1:count
    output = calculateOutput(weights,x(p),y(p));
    localerror = T_Q2(p) - output
    weights(1)= weights(1) + learningrate *localerror*x(p);
    weights(2)= weights(1) + learningrate *localerror*y(p);
    weights(3)= weights(1) + learningrate *localerror;
    globalerror = globalerror + (localerror*localerror);
  end 
end  

I out this fuunc in some other file.

function result = calculateOutput (weights, x, y)
s = x * weights(1) + y * weights(2) + weights(3);
if s >= 0
    result = 1;
else
    result = -1;
end

Nothing is coming out. I out the code in the command window and press enter….nothing apperars on the window. How do i get the output?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:24:04+00:00Added an answer on May 16, 2026 at 8:24 am

    You can’t use the variable globalerror in the condition check of your while loop because you don’t define that variable as anything until within the loop. This is why you are getting the error “Undefined function or variable ‘globalerror'”. You have to initialize globalerror to some value before you try to use it in any statements.

    Also, as I mentioned in my answer to your previous question, you can’t declare functions inside scripts. Try cutting out the function calculateOutput from the above script and place it in its own file called calculateOutput.m, then save that somewhere on the MATLAB path.

    And a few additional problems I see:

    • MATLAB uses 1-based indexing, not 0-based indexing. In other words, the first element of a vector or a matrix dimension is indexed by the value 1, not 0.
    • I have no idea what you are trying to do with this line:

      localerror = output(p) - output
      

      since the variable output is a scalar in your code, not a vector that can be indexed by p.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I load data into my grid using a WCF service. When a user clicks
I am building an application where a page will load user controls (x.ascx) dynamically
I load a single instance of a window on php-gtk, I have a button
When I load my iPhone app it always loads a black screen first then
I'm receiving Package Load Failure error when I open VS 2005 after I installed
I am trying to load Linq on my .Net 3.5 enabled web server by
The first time I load the website in the production web server, it start
How do I load a Python module given its full path? Note that the
How can I load an external JavaScript file using a bookmarklet? This would overcome
I'm trying to load a page that is basically an edit form inside a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.