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 8366735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:59:22+00:00 2026-06-09T12:59:22+00:00

I have 8 sins and cosines that I try to symbolically define as shown

  • 0

I have 8 sins and cosines that I try to symbolically define as shown below using Matlab. My goal is to symbolically build a matrix H (accumulated Givens rotations matrix) of 8×8 using all these sins and cosines and end up seeing what the formula for this H orthogonal projection matrix is. I can do that using the code below conceptually G7*G6*...*G0*I where I is the Identity 8×8 and the Gi are the Givens rotation corresponding to elements (i:i+1,i:i+1).

c_0 = sym('c_0');
c_1 = sym('c_1');
c_2 = sym('c_2');
c_3 = sym('c_3');
c_4 = sym('c_4');
c_5 = sym('c_5');
c_6 = sym('c_6');
c_7 = sym('c_7');

s_0 = sym('s_0');
s_1 = sym('s_1');
s_2 = sym('s_2');
s_3 = sym('s_3');
s_4 = sym('s_4');
s_5 = sym('s_5');
s_6 = sym('s_6');
s_7 = sym('s_7');

% create H orthogonal matrix using the sin and cos symbols
% filling in the first rotation
I=eye(9,9)
H = I;
H(1:2,1:2) = [c_0 -s_0; s_0 c_0]

% build the 2nd rotation and update H
G = I;
G(2:3,2:3) = [c_1 -s_1; s_1 c_1]
H = G*H

% build the 3rd rotation and update H
G = I;
G(3:4,3:4) = [c_2 -s_2; s_2 c_2]
H = G*H

% build the 4rth rotation and update H
G = I;
G(4:5,4:5) = [c_3 -s_3; s_3 c_3]
H = G*H

% build the 5th rotation and update H
G = I;
G(5:6,5:6) = [c_4 -s_4; s_4 c_4]
H = G*H

% build the 6th rotation and update H
G = I;
G(6:7,6:7) = [c_5 -s_5; s_5 c_5]
H = G*H

% build the 7th rotation and update H
G = I;
G(7:8,7:8) = [c_6 -s_6; s_6 c_6]
H = G*H

% build the 8th rotation and update H
G = I;
G(8:9,8:9) = [c_7 -s_7; s_7 c_7]
H = G*H

The code fails with the following error and can’t find how to fix this:

The following error occurred converting from sym to double:
Error using mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.

Error in build_rotH_test (line 26)
H(1:2,1:2) = [c_0 -s_0; s_0 c_0]
  • 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-06-09T12:59:23+00:00Added an answer on June 9, 2026 at 12:59 pm

    I solved it like this. Note I realized I need the transpose of each rotation so I can build and apply H’*x i.e. G7'*G6'*...*G0'*I that’s why the sin signs are flipped in the solution.

    clear all;
    
    % defining 0 and 1 as symbols too, solves the problem
    sym_0 = sym('0');
    sym_1 = sym('1');
    
    c0 = sym('c0');
    c1 = sym('c1');
    c2 = sym('c2');
    c3 = sym('c3');
    c4 = sym('c4');
    c5 = sym('c5');
    c6 = sym('c6');
    c7 = sym('c7');
    
    s0 = sym('s0');
    s1 = sym('s1');
    s2 = sym('s2');
    s3 = sym('s3');
    s4 = sym('s4');
    s5 = sym('s5');
    s6 = sym('s6');
    s7 = sym('s7');
    
    % create H orthogonal matrix using the sin and cos symbols
    % filling in the first rotation
    I = repmat(sym_0,9,9);
    for i=1:9
        I(i,i)=sym_1;
    end
    H = I
    H(1:2,1:2) = [c0 s0; -s0 c0]
    
    % build the 2nd rotation and update H
    G = I;
    G(2:3,2:3) = [c1 s1; -s1 c1]
    H = G*H;
    
    % build the 3rd rotation and update H
    G = I;
    G(3:4,3:4) = [c2 s2; -s2 c2]
    H = G*H;
    
    % build the 4rth rotation and update H
    G = I;
    G(4:5,4:5) = [c3 s3; -s3 c3]
    H = G*H;
    
    % build the 5th rotation and update H
    G = I;
    G(5:6,5:6) = [c4 s4; -s4 c4]
    H = G*H;
    
    % build the 6th rotation and update H
    G = I;
    G(6:7,6:7) = [c5 s5; -s5 c5]
    H = G*H;
    
    % build the 7th rotation and update H
    G = I;
    G(7:8,7:8) = [c6 s6; -s6 c6]
    H = G*H;
    
    % build the 8th rotation and update H
    G = I;
    G(8:9,8:9) = [c7 s7; -s7 c7]
    H = G*H
    

    and the output is:

    H =
    
    [ 1, 0, 0, 0, 0, 0, 0, 0, 0]
    [ 0, 1, 0, 0, 0, 0, 0, 0, 0]
    [ 0, 0, 1, 0, 0, 0, 0, 0, 0]
    [ 0, 0, 0, 1, 0, 0, 0, 0, 0]
    [ 0, 0, 0, 0, 1, 0, 0, 0, 0]
    [ 0, 0, 0, 0, 0, 1, 0, 0, 0]
    [ 0, 0, 0, 0, 0, 0, 1, 0, 0]
    [ 0, 0, 0, 0, 0, 0, 0, 1, 0]
    [ 0, 0, 0, 0, 0, 0, 0, 0, 1]
    
    
    H =
    
    [  c0, s0, 0, 0, 0, 0, 0, 0, 0]
    [ -s0, c0, 0, 0, 0, 0, 0, 0, 0]
    [   0,  0, 1, 0, 0, 0, 0, 0, 0]
    [   0,  0, 0, 1, 0, 0, 0, 0, 0]
    [   0,  0, 0, 0, 1, 0, 0, 0, 0]
    [   0,  0, 0, 0, 0, 1, 0, 0, 0]
    [   0,  0, 0, 0, 0, 0, 1, 0, 0]
    [   0,  0, 0, 0, 0, 0, 0, 1, 0]
    [   0,  0, 0, 0, 0, 0, 0, 0, 1]
    
    
    G =
    
    [ 1,   0,  0, 0, 0, 0, 0, 0, 0]
    [ 0,  c1, s1, 0, 0, 0, 0, 0, 0]
    [ 0, -s1, c1, 0, 0, 0, 0, 0, 0]
    [ 0,   0,  0, 1, 0, 0, 0, 0, 0]
    [ 0,   0,  0, 0, 1, 0, 0, 0, 0]
    [ 0,   0,  0, 0, 0, 1, 0, 0, 0]
    [ 0,   0,  0, 0, 0, 0, 1, 0, 0]
    [ 0,   0,  0, 0, 0, 0, 0, 1, 0]
    [ 0,   0,  0, 0, 0, 0, 0, 0, 1]
    
    
    G =
    
    [ 1, 0,   0,  0, 0, 0, 0, 0, 0]
    [ 0, 1,   0,  0, 0, 0, 0, 0, 0]
    [ 0, 0,  c2, s2, 0, 0, 0, 0, 0]
    [ 0, 0, -s2, c2, 0, 0, 0, 0, 0]
    [ 0, 0,   0,  0, 1, 0, 0, 0, 0]
    [ 0, 0,   0,  0, 0, 1, 0, 0, 0]
    [ 0, 0,   0,  0, 0, 0, 1, 0, 0]
    [ 0, 0,   0,  0, 0, 0, 0, 1, 0]
    [ 0, 0,   0,  0, 0, 0, 0, 0, 1]
    
    
    G =
    
    [ 1, 0, 0,   0,  0, 0, 0, 0, 0]
    [ 0, 1, 0,   0,  0, 0, 0, 0, 0]
    [ 0, 0, 1,   0,  0, 0, 0, 0, 0]
    [ 0, 0, 0,  c3, s3, 0, 0, 0, 0]
    [ 0, 0, 0, -s3, c3, 0, 0, 0, 0]
    [ 0, 0, 0,   0,  0, 1, 0, 0, 0]
    [ 0, 0, 0,   0,  0, 0, 1, 0, 0]
    [ 0, 0, 0,   0,  0, 0, 0, 1, 0]
    [ 0, 0, 0,   0,  0, 0, 0, 0, 1]
    
    
    G =
    
    [ 1, 0, 0, 0,   0,  0, 0, 0, 0]
    [ 0, 1, 0, 0,   0,  0, 0, 0, 0]
    [ 0, 0, 1, 0,   0,  0, 0, 0, 0]
    [ 0, 0, 0, 1,   0,  0, 0, 0, 0]
    [ 0, 0, 0, 0,  c4, s4, 0, 0, 0]
    [ 0, 0, 0, 0, -s4, c4, 0, 0, 0]
    [ 0, 0, 0, 0,   0,  0, 1, 0, 0]
    [ 0, 0, 0, 0,   0,  0, 0, 1, 0]
    [ 0, 0, 0, 0,   0,  0, 0, 0, 1]
    
    
    G =
    
    [ 1, 0, 0, 0, 0,   0,  0, 0, 0]
    [ 0, 1, 0, 0, 0,   0,  0, 0, 0]
    [ 0, 0, 1, 0, 0,   0,  0, 0, 0]
    [ 0, 0, 0, 1, 0,   0,  0, 0, 0]
    [ 0, 0, 0, 0, 1,   0,  0, 0, 0]
    [ 0, 0, 0, 0, 0,  c5, s5, 0, 0]
    [ 0, 0, 0, 0, 0, -s5, c5, 0, 0]
    [ 0, 0, 0, 0, 0,   0,  0, 1, 0]
    [ 0, 0, 0, 0, 0,   0,  0, 0, 1]
    
    
    G =
    
    [ 1, 0, 0, 0, 0, 0,   0,  0, 0]
    [ 0, 1, 0, 0, 0, 0,   0,  0, 0]
    [ 0, 0, 1, 0, 0, 0,   0,  0, 0]
    [ 0, 0, 0, 1, 0, 0,   0,  0, 0]
    [ 0, 0, 0, 0, 1, 0,   0,  0, 0]
    [ 0, 0, 0, 0, 0, 1,   0,  0, 0]
    [ 0, 0, 0, 0, 0, 0,  c6, s6, 0]
    [ 0, 0, 0, 0, 0, 0, -s6, c6, 0]
    [ 0, 0, 0, 0, 0, 0,   0,  0, 1]
    
    
    G =
    
    [ 1, 0, 0, 0, 0, 0, 0,   0,  0]
    [ 0, 1, 0, 0, 0, 0, 0,   0,  0]
    [ 0, 0, 1, 0, 0, 0, 0,   0,  0]
    [ 0, 0, 0, 1, 0, 0, 0,   0,  0]
    [ 0, 0, 0, 0, 1, 0, 0,   0,  0]
    [ 0, 0, 0, 0, 0, 1, 0,   0,  0]
    [ 0, 0, 0, 0, 0, 0, 1,   0,  0]
    [ 0, 0, 0, 0, 0, 0, 0,  c7, s7]
    [ 0, 0, 0, 0, 0, 0, 0, -s7, c7]
    
    
    H =
    
    [                       c0,                       s0,                     0,                  0,               0,            0,         0,      0,  0]
    [                   -c1*s0,                    c0*c1,                    s1,                  0,               0,            0,         0,      0,  0]
    [                 c2*s0*s1,                -c0*c2*s1,                 c1*c2,                 s2,               0,            0,         0,      0,  0]
    [             -c3*s0*s1*s2,              c0*c3*s1*s2,             -c1*c3*s2,              c2*c3,              s3,            0,         0,      0,  0]
    [           c4*s0*s1*s2*s3,          -c0*c4*s1*s2*s3,           c1*c4*s2*s3,          -c2*c4*s3,           c3*c4,           s4,         0,      0,  0]
    [       -c5*s0*s1*s2*s3*s4,        c0*c5*s1*s2*s3*s4,       -c1*c5*s2*s3*s4,        c2*c5*s3*s4,       -c3*c5*s4,        c4*c5,        s5,      0,  0]
    [     c6*s0*s1*s2*s3*s4*s5,    -c0*c6*s1*s2*s3*s4*s5,     c1*c6*s2*s3*s4*s5,    -c2*c6*s3*s4*s5,     c3*c6*s4*s5,    -c4*c6*s5,     c5*c6,     s6,  0]
    [ -c7*s0*s1*s2*s3*s4*s5*s6,  c0*c7*s1*s2*s3*s4*s5*s6, -c1*c7*s2*s3*s4*s5*s6,  c2*c7*s3*s4*s5*s6, -c3*c7*s4*s5*s6,  c4*c7*s5*s6, -c5*c7*s6,  c6*c7, s7]
    [  s0*s1*s2*s3*s4*s5*s6*s7, -c0*s1*s2*s3*s4*s5*s6*s7,  c1*s2*s3*s4*s5*s6*s7, -c2*s3*s4*s5*s6*s7,  c3*s4*s5*s6*s7, -c4*s5*s6*s7,  c5*s6*s7, -c6*s7, c7]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have got a method which returns IEnumerable<User> which I have been using Linq /
Have a chat room, issue is, is that when you submit something, the message
Have a photography site that I want to prevent image copying from. How can
Have you ever seen someone try to implement the MVP pattern with ASP.NET Web
Have a problem that seems easy on paper but i'm having a big problem
Have a query that should hopefully be nice and simple to answer. I have
Have a web service that implements REST (sort of) , Client request is made
I have a project that uses GLSL shaders. This project is designed not to
Have a look at this code: #include <iostream> using namespace std; int main() {
I have an old site with many old sins in it's source and one

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.